我有一个在某个端口上运行的 express.js 应用程序和这个nginx
配置:
server {
server_name example.com;
access_log /var/www/example/log/nginx.access.log;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:3000;
}
}
提供包含如下脚本index.html
的路线:/source
<script src="/source/assets/js/script.js"></script>
问题是它无法加载此脚本,请求导致502 Bad Gateway
.
尽管
curl http://example.com/source/assets/js/script.js
工作正常,在浏览器中输入这个 url 也是如此......只是引用 fromindex.html
不......与style.css
.
在日志中我看到这个:
90.100.44.55 - - [26/Mar/2016:22:47:13 +0000] "GET /source/assets/js/script.js HTTP/1.1" 502 574 "http://example.com/source" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"
有效的直接请求(curl 或浏览器)如下所示:
90.100.44.55 - - [26/Mar/2016:22:47:24 +0000] "GET /source/assets/js/script.js HTTP/1.1" 200 8358 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"
有任何想法吗?
更新:
我启用了 nginx 错误日志:
2016/03/27 00:26:36 [error] 32079#0: *319759 connect() failed (111: Connection refused) while connecting to upstream, client: 90.100.44.55, server: example.com, request: "GET /source/assets/css/styles.css HTTP/1.1", upstream: "http://127.0.0.1:3011/source/assets/css/styles.css", host: "example.com", referrer: "http://example.com/source"
但是当我这样做时
http://127.0.0.1:3011/source/assets/css/styles.css
在服务器上,它可以工作:/
这是
pm2
问题:nginx: connect() failed (111: Connection refused) while connection to upstream这个解决方案(127.0.0.1 而不是
localhost
)对我不起作用......我查看了
pm2
日志,发现这是问题所在(我也在使用node-config
):https ://github.com/lorenwest/node-config/issues/244我想
pm2
对于生产来说还不够好,我将尝试Phusion Passenger
使用节点。我仍然不知道 pm2 如何设法看到
curl
与来自浏览器的请求之间的任何区别......但无论如何,唯一的解决方案似乎是不使用pm2