## 我把 log 在 google 上搜了一下,很多人描述这个问题,我也尝试了 2 天了,都搞不定,特来求助
## 环境:
- Node.js v8.9.1
- ExpressJS
- Ubuntu 16.04 LTS
- pm2
## 错误
- 描述 1:如果短时间内多次刷新首页,出现 502 Bad Gateway 错误
- 描述 2:代码里,用户注册或登陆成功后会自动跳转到首页,在本机 OK,但部署到服务器之后,跳转出现 502 Bad Gateway
## 配置:
### Nginx 配置文件:
1 upstream helloworld {
2 server <server-ip-address>:3000 max_fails=0 fail_timeout=10s weight=1;
3 ip_hash;
4 keepalive 512;
5 }
6
7 server {
8 listen 80;
9 server_name
helloworld.com www.helloworld.com;
10
11 #charset koi8-r;
12 access_log /app/archives/logs/nginx/helloworld .host.access.log main;
13 error_log /app/archives/logs/nginx/helloworld .host.error.log debug;
14
15 root /app/helloworld ;
16
17 location / {
18 proxy_pass http://helloworld;
19 proxy_set_header X-Real-IP $remote_addr;
20 proxy_set_header X-Forwarded-Proto $scheme;
21 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
22 proxy_set_header Host $host;
23 proxy_set_header X-NginX-Proxy true;
24 proxy_http_version 1.1;
25 proxy_set_header Upgrade $http_upgrade;
26 proxy_set_header Connection 'upgrade';
27 proxy_set_header Host $host;
28 proxy_cache_bypass $http_upgrade;
29
30 }
31 }
## error log
2017/12/11 09:22:23 [error] 29952#29952: *81 connect() failed (111: Connection refused) while connecting to upstream, client: 169.228.200.160, server:
helloworld.com, request: "GET / HTTP/1.1", upstream: "http://<server-ip-address>:3000/", host: "
www.helloworld.com", referrer: "
http://www.helloworld.com/user/signin"
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/413940
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.