nginx导致504错误,但我的应用程序仍在运行

因此,我们使用Node.js来为CompassionPit.com提供动力,并且全部由nginx提供。

nginx正在抛出一个504网关超时

有趣的是,如果我导航到http://compassionpit.com/index.html ,那么我可以访问该页面(我相信所请求的是通过端口8000上运行的节点应用程序路由)。

和http://compassionpit.com/blog/正在工作。

但http://compassionpit.com/已closures。 🙁

帮帮我?

root@li70-243:~# cat /etc/nginx/sites-enabled/blog server { listen 80 default; # your server's public IP address server_name compassionpit.com; index index.html; location /blog/wp-content/ { alias /opt/blog/wp-content/; } location /blog/ { root /opt/; include fastcgi_params; fastcgi_pass localhost:8080; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location / { alias /opt/chat/static/; if (-f $request_filename) { break; } if (!-f $request_filename) { proxy_pass http://127.0.0.1:8000; } } } 

 root@li70-243:~# cat /etc/nginx/nginx.conf user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; # multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 

 root@li70-243:~# free total used free shared buffers cached Mem: 509868 394168 115700 0 43540 215296 -/+ buffers/cache: 135332 374536 Swap: 524284 0 524284 

试试这个,而不是你的location /

 location / { alias /opt/chat/static/; try_files $uri @nodejs; } location @nodejs { proxy_pass http://127.0.0.1:8000; } 

并经常检查error.log ,这是你最好的朋友。

我也发现Linux上的csf禁止许多连接的节点可执行文件。 解决scheme是将节点pid添加到csf.pignore ,像这样(我也包括PM2path):

... exe:/usr/local/bin/node exe:/root/npm/lib/node_modules/pm2/bin/pm2