Nginx returns 404 对于某些子域,但对于其他子域则不是
Nginx returns 404 for some sub domains but not for others
所以我正在尝试设置 5 个网站,所有网站都在同一个域中,只是具有不同的子域,等等 www.和cdn。
但万维网。正常工作,因为它应该
你 cdn。不,它得到了我刚刚复制的相同文件,文件夹的所有权限都是相同的。
我在自己的文件中有每个子域等 wwwmydomaincom 和 cdnmydomaincom 并且配置是相同的,唯一的区别是 server_name。有效的文件得到 www.mydomain.com 其余的得到 somesubdomain.mydomain.com 并且他们抛出 404.
我在 ubuntu 服务器 16.04.1.
上使用 Nginx
已添加
location / {
try_files $uri.html;
}
并且子域可以很好地显示 html 页面(现在它们的配置与有效的配置一样)
但是.. 每个资产、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(\?.*)?$ permanent;
#rewrite ^/(.*)/$ / permanent;
error_page 404 /404.php;
error_page 500 503 502 504 /error/40x.php;
location =/error/40x.html {
internal;
}
}
咳咳,这就是我想学这种东西的原因
您显然需要让它查找文件。
因此,如果有人进入这种小情况,请不要忘记在根文件夹中查看它。
location / {
try_files $uri $uri/ $uri.html @rewrite;
}
所以我正在尝试设置 5 个网站,所有网站都在同一个域中,只是具有不同的子域,等等 www.和cdn。 但万维网。正常工作,因为它应该 你 cdn。不,它得到了我刚刚复制的相同文件,文件夹的所有权限都是相同的。 我在自己的文件中有每个子域等 wwwmydomaincom 和 cdnmydomaincom 并且配置是相同的,唯一的区别是 server_name。有效的文件得到 www.mydomain.com 其余的得到 somesubdomain.mydomain.com 并且他们抛出 404.
我在 ubuntu 服务器 16.04.1.
上使用 Nginx已添加
location / {
try_files $uri.html;
}
并且子域可以很好地显示 html 页面(现在它们的配置与有效的配置一样) 但是.. 每个资产、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(\?.*)?$ permanent;
#rewrite ^/(.*)/$ / permanent;
error_page 404 /404.php;
error_page 500 503 502 504 /error/40x.php;
location =/error/40x.html {
internal;
}
}
咳咳,这就是我想学这种东西的原因
您显然需要让它查找文件。
因此,如果有人进入这种小情况,请不要忘记在根文件夹中查看它。
location / {
try_files $uri $uri/ $uri.html @rewrite;
}