我正在使用nginx配置我的node.js应用程序。它适用于http,但它不适用于https。当我尝试访问安全域时。我收到这个错误。
502 Bad Gateway
nginx/1.4.6 (Ubuntu)
这是我的nginx配置文件
upstream node_app_dev {
server 127.0.0.1:3000;
}
upstream node_app_production {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name mydomain.com;
access_log /var/log/nginx/dev.log;
error_log /var/log/nginx/dev.error.log debug;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://node_app_dev;
proxy_redirect off;
}
}
server {
listen 443 ssl;
server_name mydomain.com;
access_log /var/log/nginx/secure.log;
error_log /var/log/nginx/secure.error.log debug;
ssl on;
ssl_certificate certs/mycert.crt;
ssl_certificate_key certs/mykey.key;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass https://node_app_production;
proxy_redirect off;
}
}
答案 0 :(得分:17)
替换
>>> from operator import itemgetter
>>> list_ = [{'x':1,'y':2},{'x':1,'y':1},{'x':3,'y':3}]
>>> sorted(list_,key=itemgetter('x','y'))
[{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 3, 'y': 3}]
带
proxy_pass https://node_app_production;
重新启动nginx,你应该全部设置好。 见nginx proxy pass Node, SSL?
答案 1 :(得分:-1)
我已通过2个步骤解决了该问题。
/var/log/nginx/error.log
connect() failed (111: Connection refused) while connecting to upstream, client: *.*.*.*, server: *.*.*.*, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "*.*.*.*"
即使我在nginx conf文件中将上游设置为127.0.0.1:8000
,上游仍然是127.0.0.1:3000
。
server 127.0.0.1:8000
替换为server 127.0.0.1:3000
,然后重新启动nginx。/etc/nginx/conf.d/virtual.conf
server {
listen 80;
server_name SERVER_IP_ADDRESS;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
最后,它没有502错误。