我正在尝试配置我的NGINX以处理来自两个不同子域的请求,将它们路由到运行在端口3000和9000上的两个不同的nodeJS应用。我还将所有端口80请求路由到443。这就是我的配置:
# Catch non-ssl domain requests
server {
listen 80;
listen [::]:80;
server_name schandillia.com www.schandillia.com;
return 301 https://www.$server_name$request_uri;
}
# Catch non-www domain requests on ssl
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name schandillia.com;
return 301 https://www.$server_name$request_uri;
}
# Settings for TLS enabled server (www/ssl requests)
server {
listen 443 default_server ssl http2;
listen [::]:443 ssl http2;
server_name www.schandillia.com;
# Retrieve certificates
ssl_certificate "/etc/letsencrypt/live/schandillia.com/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/schandillia.com/privkey.pem";
# Automatically route HTTP to HTTPS
add_header Strict-Transport-Security "max-age=31536000";
include /etc/nginx/default.d/*.conf;
root /usr/share/nginx/html;
index index.html index.htm;
proxy_hide_header X-Powered-By;
add_header X-Powered-By "Project Proost 0.0.0";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
location / {
proxy_pass http://127.0.0.1:3000;
charset UTF-8;
proxy_http_version 1.1;
}
location ~* \.(?:ico|svg|woff|woff2|ttf|otf|css|js|gif|jpe?g|png)$ {
proxy_pass http://127.0.0.1:3000;
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}
}
# for subdomain graph
server {
listen 443 default_server ssl http2;
listen [::]:443 ssl http2;
server_name graph.schandillia.com;
location / {
proxy_pass http://127.0.0.1:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
很明显,我的配置中有4个服务器块。第一个处理所有非SSL请求,第二个处理非WWW SSL请求到WWW,第三个处理所有请求到https://www.schandillia.com,将它们路由到端口3000。
在第4个块中,我正在处理来自子域graph.schandillia.com的请求,并尝试将其路由到端口9000。但这会引发错误,并且没有错误代码:
nginx.service的作业失败,因为控制进程退出 错误代码。
我要去哪里错了?
P.S。:nginx -t
返回以下日志:
nginx: [emerg] a duplicate default server for 0.0.0.0:443 in /etc/nginx/sites-enabled/default:56
nginx: configuration file /etc/nginx/nginx.conf test failed
此外,在删除最后一个服务器块后,配置似乎可以正常工作。但这不符合我的目的,因为我确实需要一个服务器块来处理graph
子域请求。