我的nginx.conf几乎是添加了后备服务器块的默认conf:
user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # 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; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## # fallback-server if host is not known server { listen 80 default_server; server_name _; return 404; } include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
文件夹/etc/nginx/conf.d/是空的。
启用站点包含以下configuration文件的符号链接:
server { listen 80; server_name www.subdomain.example.com subdomain.example.com; root /var/www/subdomain; index index.html; location / { try_files $uri $uri/ =404; } }
问题在于,nginx始终默认回退服务器,即使对于具有subdomain.example.com请求也是如此。
删除后备服务器会导致子域服务器提供所有的请求,据我所知,这是默认的nginx行为。
这是我喜欢扩展为服务多个子域的testing设置。 为第二个子域添加第二个服务器也会导致只有一个服务器提供所有请求。
nginx access.log摘录(2个最近的请求):
XX.XXX.XXX.XXX - - [17/Aug/2017:18:13:32 +0200] "GET / HTTP/1.1" 404 152 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 Mobile/14G60 Safari/602.1" XX.XXX.XXX.XXX - - [17/Aug/2017:18:14:17 +0200] "GET / HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
nginx error.log摘录(最后2项)
2017/08/17 16:11:53 [notice] 3829#3829: signal process started 2017/08/17 16:32:10 [notice] 3914#3914: signal process started
我的问题:
dig也会返回一个答案部分。 当然,我对此做了一些研究,但无法弄清楚什么是错的:
更新
nginx -t结果
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2017/08/18 08:03:51 [warn] 6200#6200: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2017/08/18 08:03:51 [emerg] 6200#6200: open() "/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed
sudo nginx -t结果
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
更新2
不确定这是否相关。 删除所有服务器阻止请求后, subdomain.example.com导致503 Service Temporarily Unavailable站点。 请求XX.XXX.XXX.XXX:80导致浏览器告诉我无法打开页面。
另外,我尝试在子域服务器块中的不同位置服务, 但是,我错误地configuration了一个使用root而不是alias的位置,并返回了/var/www/html的默认nginx页面,这个页面无处设置为根目录或别名目录。 这怎么可能?