Nginx为某些子域返回404,但对其他子域则不返回

时间:2017-02-10 14:39:41

标签: nginx http-status-code-404

所以我试图设置5个网站,所有这些网站都在同一个域名上,只有不同的子域名等等。和cdn。 但是www。工作得很好 通过cdn。没有,它有我刚刚复制过的相同文件,文件夹的所有权限都是相同的。 我有自己的文件中的每个子域等wwwmydomaincom和cdnmydomaincom,配置是相同的,只有diffrence是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(\?.*)?$ $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;
  }
}

1 个答案:

答案 0 :(得分:0)

嗯,这就是我想学习这种东西的原因。

你显然需要让它找到文件。

所以,如果有人进入这种情况,请不要忘记让它看到根文件夹。

location / {
  try_files $uri $uri/ $uri.html @rewrite;
}
相关问题