Nginx 子域名 404

Nginx 子域名 404

(我提前为这篇文章中的配置量道歉。我已经为此花了几个小时,而且我对 Nginx 还很陌生,所以我不想排除一些可能相关的东西。)

我试图在一台 Ubuntu 服务器(Linode,如果这有区别的话)上托管多个 Wordpress 网站。我正在使用 Nginx。主域运行良好,但对子域的每个请求都返回 404。

配置——我主要从Wordpress 的文档— 布局如下:

/etc/nginx/nginx.conf是主配置文件。内容如下:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
}

http {

    sendfile on;
    #tcp_nopush on;
    #tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;


    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Upstream PHP
    ##

    upstream php {
        server unix:/tmp/php-fpm.sock;
        server 127.0.0.1:9000;
    }

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log debug;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/global/wordpress.conf包含在我的条目的顶部sites-available,如下所示:

server {
    listen 80;
    listen [::]:80;

        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
                fastcgi_buffers 16 16k;
                fastcgi_buffer_size 32k;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
#                log_not_found off;
        }
}

/etc/nginx/global/wp-restrictions.conf这是:

location = /favicon.ico {
    log_not_found off;
    access_log off;
}
# robots.txt fallback to index.php
location = /robots.txt {
# Some WordPress plugin gererate robots.txt file
    allow all;
    try_files $uri $uri/ /index.php?$args @robots;
    access_log off;
    log_not_found off;
}

location @robots {
   return 200 "User-agent: *\nDisallow: /wp-admin/\nAllow: /wp-admin/admin-ajax.php\n";
}


location ~ /\.(?!well-known\/) {
    deny all;
}

location /wp-content/uploads {
    location ~ \.php$ {
        deny all;
    }
}


location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

这是 中主域的条目sites-available。这个可以正常工作:

server {

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html index.php;

    server_name mydomain.site www.mydomain.site;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

以下是导致我出现 404 错误的子域名条目:

server {

    include global/wordpress.conf;
    include global/wp-restrictions.conf;

    server_name sub.mydomain.site;

    root /var/www/microsites/lgw/;

    index index.php;
}

我做了一些事情来证实这一点应该工作:

  • 子域的 DNS 配置已正确。
  • 子域 a) 的 Doc 根目录存在,并且 b) 其中包含文件。如果我尝试按名称访问任何文件,则会得到 404。
  • php-fpm 正在运行。
  • 所有域名或目录名称均无拼写错误
  • 每次配置更改后我都会重新启动 nginx
  • 错误日志仅在我debug打开时才显示错误。否则,当我发出返回 404 的请求时,我会得到 bupkis。

不确定这里还要包含什么。根据我能找到的所有操作指南,这应该可行。但事实并非如此。

如果您能提供任何有关我做错什么的提示,我将不胜感激。如果我能提供其他信息,让回答这个问题变得更容易,请告诉我。

谢谢!

相关内容