我正在学习nginx。我不明白为什么浏览器地址栏中的server_name导致找不到页面(例如mydomain / app2.com,但是目录的位置很好(例如mydomain / app2))。我确实知道server_name找不到评估listen指令是否是结论性的。 我有一个[webroot] /app2/index.html文件,其中显示了一条简单消息。
以下是使用命令nginx -T生成的nginx.conf的编辑部分。
worker_processes auto;
#worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
include conf.d/main.conf;
events {
use epoll;
multi_accept on;
accept_mutex off;
worker_connections 1024;
include conf.d/events.conf;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log off;
#access_log syslog:server=unix:/dev/log,facility=local7,tag=nginx_access,nohostname main;
error_log syslog:server=unix:/dev/log,facility=local7,tag=nginx_error,nohostname error;
tcp_nopush on;
tcp_nodelay on;
sendfile on;
server_tokens off;
proxy_request_buffering off;
fastcgi_request_buffering off;
scgi_request_buffering off;
proxy_buffering off;
fastcgi_buffering off;
scgi_buffering off;
resolver_timeout 5s;
client_header_timeout 10s;
client_body_timeout 60s;
send_timeout 60s;
keepalive_timeout 65s 20s;
client_max_body_size 0;
server_names_hash_max_size 8192;
server_names_hash_bucket_size 128;
ssl_certificate /usr/syno/etc/certificate/system/default/fullchain.pem;
ssl_certificate_key /usr/syno/etc/certificate/system/default/privkey.pem;
ssl_protocols TLSv1.2;
ssl_dhparam /usr/syno/etc/ssl/dh2048.pem;
ssl_prefer_server_ciphers on;
ssl_session_tickets off;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 3600s;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
set_real_ip_from 127.0.0.1;
include /var/tmp/nginx/trusted_proxy/*.conf;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server_tag "nginx";
gzip_disable "msie6";
gzip_min_length 1000;
gzip_types text/plain text/css application/javascript application/json;
gzip_vary on;
gzip_static on;
open_file_cache max=1000 inactive=60s;
open_file_cache_valid 3s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
upstream synoscgi {
server unix:/run/synoscgi.sock;
}
index index.html index.htm index.php;
server {
listen 80 default_server;
listen [::]:80 default_server;
gzip on;
server_name _;
location ~ ^/volume(?:X|USB|SATA|Gluster)?\d+/ {
internal;
root /;
open_file_cache off;
include app.d/x-accel.*.conf;
include conf.d/x-accel.*.conf;
}
include app.d/www.*.conf;
include app.d/alias.*.conf;
include /usr/syno/share/nginx/conf.d/www.*.conf;
include conf.d/www.*.conf;
location = /webdefault/images/logo.jpg {
alias /usr/syno/share/nginx/logo.jpg;
}
error_page 403 404 500 502 503 504 @error_page;
location @error_page {
root /usr/syno/share/nginx;
rewrite (.*) /error.html break;
allow all;
}
location ^~ /.well-known/acme-challenge {
root /var/lib/letsencrypt;
default_type text/plain;
}
include app.d/.location.webstation.conf*;
location / {
rewrite ^ / redirect;
}
location ~ ^/$ {
rewrite / http://$host:5000/ redirect;
}
}
}
# configuration file /etc/nginx/app.d/dsm.DownloadStation.conf:
location ~ ^/volume(?:X|USB|SATA|Gluster)?\d+/ {
internal;
root /;
open_file_cache off;
include app.d/x-accel.*.conf;
include conf.d/x-accel.*.conf;
}
location ~ ^/download/btsetting.cgi {
rewrite /download/btsetting.cgi /webman/3rdparty/DownloadStation/dlm/btsetting.cgi break;
include scgi_params;
scgi_pass synoscgi;
}
location ~ ^/webman/modules/DownloadStation/dlm/(.*) {
rewrite /webman/modules/DownloadStation/dlm/(.*) /webman/3rdparty/DownloadStation/dlm/$1 break;
include scgi_params;
scgi_pass synoscgi;
}
uninitialized_variable_warn off;
if ($fqdn = false) {
set $fqdn "";
}
scgi_param HOST $fqdn if_not_empty;
scgi_intercept_errors on;
# configuration file /etc/nginx/app.d/.location.webstation.conf:
location ~ ^/~([^\/]*)/ {
proxy_ignore_headers X-Accel-Redirect;
proxy_read_timeout 3600s;
proxy_set_header X-Forwarded-By $server_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-HTTPS $https;
proxy_set_header X-Port $server_port;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_intercept_errors off;
error_page 404 /_webstation_/404.html;
return 404;
}
location ^~ /_webstation_/ {
alias /var/packages/WebStation/target/error_page/;
}
location ~ ^ {
proxy_ignore_headers X-Accel-Redirect;
proxy_read_timeout 3600s;
proxy_set_header X-Forwarded-By $server_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-HTTPS $https;
proxy_set_header X-Port $server_port;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_intercept_errors off;
error_page 502 /_webstation_/$status.html;
proxy_pass http://unix:/run/webstation_default.sock;
}
# configuration file /etc/nginx/app.d/server.webstation-vhost.conf:
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
server_name app3.com;
location ^~ /.well-known/acme-challenge {
root /var/lib/letsencrypt;
default_type text/plain;
}
root "/volume1/web/app3";
index index.html index.htm index.cgi index.php index.php5 ;
error_page 400 401 402 403 404 405 406 407 408 500 501 502 503 504 505 @error_page;
location @error_page {
root /var/packages/WebStation/target/error_page;
rewrite ^ /$status.html break;
}
location ^~ /_webstation_/ {
alias /var/packages/WebStation/target/error_page/;
}
include /usr/local/etc/nginx/conf.d/05d0bb2f-bd06-4069-ba12-eb4f67b58137/user.conf*;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
server_name app2.com;
location ^~ /.well-known/acme-challenge {
root /var/lib/letsencrypt;
default_type text/plain;
}
root "/volume1/web/app2";
index index.html index.htm index.cgi index.php index.php5 ;
error_page 400 401 402 403 404 405 406 407 408 500 501 502 503 504 505 @error_page;
location @error_page {
root /var/packages/WebStation/target/error_page;
rewrite ^ /$status.html break;
}
location ^~ /_webstation_/ {
alias /var/packages/WebStation/target/error_page/;
}
include /usr/local/etc/nginx/conf.d/e0fd8b64-e801-426b-86b6-c0035b4ae9d7/user.conf*;
}
# configuration file /etc/nginx/app.d/server.webstation.conf:
server {
listen unix:/run/webstation_default.sock;
root /var/services/web;
index index.html index.php index.cgi;
set_real_ip_from unix:;
real_ip_header X-Real-IP;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $http_x_https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $http_x_real_port;
fastcgi_param SERVER_ADDR $http_x_forwarded_by;
fastcgi_param SERVER_PORT $http_x_port;
fastcgi_param SERVER_NAME $host;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_intercept_errors on;
fastcgi_read_timeout 3600s;
error_page 400 401 402 403 404 405 406 407 408 500 501 502 503 504 505 @error_page;
location @error_page {
root /var/packages/WebStation/target/error_page;
rewrite ^ /$status.html break;
}
location ^~ /_webstation_/ {
alias /var/packages/WebStation/target/error_page/;
}
location ~* \.(php[345]?|phtml)$ {
fastcgi_pass unix:/run/php-fpm/php-9f1e642a-0d20-4664-8934-c51d34f609de.sock;
}
location ~* \.cgi {
fastcgi_pass unix:/run/fcgiwrap.sock;
}
}