Nginx返回404的一些子域名,但不为其他人

问题描述:

因此,我试图设置5个网站,所有在相同的域只是与不同的子域名等www。和cdn。 但www。工作正常,因为它应该 tho cdn。没有,它得到了我刚把它们复制过来的相同文件,这些文件夹的所有权限都是相同的。 我有他们自己的文件等wwwmydomaincom和cdnmydomaincom中的每个子域和配置是相同的,只有差异是server_name。该作品的文件得到www.mydomain.com其余的得到somesubdomain.mydomain.com,他们扔404。Nginx返回404的一些子域名,但不为其他人

我使用的Nginx的Ubuntu的服务器16.04.1。

新增

location/{ 
    try_files $uri.html; 
} 

和子域显示HTML页面罚款(目前其配置isent喜欢的作品之一) 但是...每一项资产,CSS,JS,图像或其他事情就这么404这是一个纯粹的HTML页面。

的配置下是完全相同的配置为www.mydomain.com但经过修改以适应cdn.mydomain.com

server { 
    listen 80; 
    server_name cdn.domain.com; 
    location /.well-known/acme-challenge { 
    default_type "text/plain"; 
    root /storage/webserver/certbot; 
    } 

    #Forces all other requests to HTTPS 
    location/{ 
    return 301 https://$host$request_uri; 
    } 
} 
server { 
    listen 443 ssl http2; 
    server_name cdn.domain.com; 
    ssl_certificate /etc/letsencrypt/live/cdn.domain.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/cdn.domain.com/privkey.pem; 
    ssl_dhparam /etc/ssl/certs/dhparam.pem; 
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1; 
    ssl_prefer_server_ciphers on; 
    ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA512:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:ECDH+AESGCM:ECDH+AES256:DH+AESGCM:DH+AES256:RSA+AESGCM:!aNULL:!eNULL:!LOW:!RC4:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS; 
    ssl_session_cache shared:TLS:2m; 
    # OCSP stapling 
    ssl_stapling on; 
    ssl_stapling_verify on; 
    resolver 8.8.8.8; 
    # Set HSTS to 365 days 
    add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains'; 
    root /storage/webserver/cdn.domain.com; 
    index index.html index.php; 
    location @rewrite { 
    rewrite^$uri.php last; 
    try_files $uri =404; 
    } 
    location ~ \.php$ { 
    fastcgi_split_path_info ^(.+?\.php)(/.+)$; 
    fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 
    include fastcgi.conf; 
    try_files $uri =404; 
    } 
    rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent; 
    #rewrite ^/(.*)/$ /$1 permanent; 
    error_page 404 /404.php; 
    error_page 500 503 502 504 /error/40x.php; 
    location =/error/40x.html { 
    internal; 
    } 
} 

咳咳,这就是为什么我要学这种东西。

您明显需要使其查找文件。

所以,如果有人进入这个litte情况,不要忘记让它看起来在根文件夹。

location/{ 
    try_files $uri $uri/ $uri.html @rewrite; 
}