【发布时间】:2018-01-05 04:37:53
【问题描述】:
我正在尝试使用 nginx 反向代理后面的 nodejs 应用程序来处理 ssl
我的应用程序在 localhost:2000 上运行。我可以确认这是使用 curl 命令。
这是我的 nginx 设置:
# the IP(s) on which your node server is running. I chose port 3000.
upstream dreamingoftech.uk {
server 127.0.0.1:2000;
keepalive 16;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name dreamingoftech.uk;
return 301 https://$host$request_uri;
}
#HTTPS
server {
listen 443 ssl http2;
server_name dreamingoftech.uk;
access_log /var/log/nginx/dreamingoftech.log;
error_log /var/log/nginx/dreamingoftech.error.log debug;
ssl_certificate /etc/letsencrypt/live/dreamingoftech.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dreamingoftech.uk/privkey.pem;
include snippets/ssl-params.conf;
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://dreamingoftech.uk/;
proxy_redirect off;
#proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "";
proxy_ssl_session_reuse off;
proxy_cache_bypass $http_upgrade;
}
}
如果我现在 curl https://dreamingoftech.uk,这需要一段时间,但我确实收到了网页。尽管带有消息:
curl: (18) 传输关闭,剩余 1 个字节要读取
但是,当从浏览器查看时,我收到 502 网关错误。
我检查了错误日志,结果如下:ERROR LOG
我不明白为什么反向代理会在流程中添加这样的时间延迟。任何想法将不胜感激。
PS:在上游配置中,我尝试使用 localhost 而不是 127.0.0.1 无济于事
【问题讨论】:
-
你确定你的应用程序在代理后面没有不同的行为,比如基于远程 IP 的行为不同吗?
-
@BrahmaDev 老实说,我不知道......我现在正在努力学习所有这些,所以我不知道如何测试?
标签: node.js nginx nginx-reverse-proxy