![nginx 导致 504 错误,但我的应用程序仍在运行](https://linux22.com/image/547561/nginx%20%E5%AF%BC%E8%87%B4%20504%20%E9%94%99%E8%AF%AF%EF%BC%8C%E4%BD%86%E6%88%91%E7%9A%84%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E4%BB%8D%E5%9C%A8%E8%BF%90%E8%A1%8C.png)
所以,我们使用 Node.js 来支持 CompassionPit.com,并且全部由 nginx 提供服务。
nginx 抛出 504 网关超时
然而有趣的是,如果我导航到http://compassionpit.com/index.html然后我就可以访问该页面(我相信请求是通过在端口 8000 上运行的 Node 应用程序路由的)。
和http://compassionpit.com/blog/工作中。
但http://compassionpit.com/已关闭。:(
帮助?
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
答案1
尝试这个而不是你的location /
:
location / {
alias /opt/chat/static/;
try_files $uri @nodejs;
}
location @nodejs {
proxy_pass http://127.0.0.1:8000;
}
并经常检查error.log
,它是你最好的朋友。
答案2
我还发现 Linux 上的 csf 禁止许多连接的节点可执行文件。解决此问题的方法是将节点 pid 添加到csf.pignore
,如下所示(我还包含了 PM2 路径):
... exe:/usr/local/bin/node exe:/root/npm/lib/node_modules/pm2/bin/pm2