【发布时间】:2017-06-03 14:35:05
【问题描述】:
我正在尝试部署一个通过 https 托管两个 node.js Express 应用程序的 NGINX 服务器。
我的主站点(在端口 80 上提供服务的站点)是一个在端口 8001 上运行的 Express 应用程序。(即https://example.com 加载此应用程序)
我还在端口 8002 上运行另一个 Express 应用程序,我希望在端口 8080 上公开可用。(即https://example.com:8080 加载此应用程序)
这是我的/etc/nginx/sites-available/default 文件:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com www.example.com;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
# Pass requests for / to localhost:8001:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8001/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location ~ /.well-known {
allow all;
}
}
server {
listen 8080 ssl;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
# pass requests to port 8002 where our other node server is running
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8002/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
如果有任何其他帮助,我一直在遵循 DigitalOcean 指南来配置 https 和 NGINX here 和 here.
【问题讨论】:
-
你能解释一下是什么问题吗?
-
@FarhadFarahi 问题是尝试从公共访问
http://example.com:8080或https://example.com:8080导致超时而没有响应。在本地访问这些相同的路由(来自服务器本身的curl),在 https 路由上返回成功,但在 http 路由上返回400 The plain HTTP request was sent to HTTPS port。
标签: linux redirect nginx https