nginx - EC2 节点后端应用程序 [504 网关超时]
问题描述
工作了几个小时,然后我在应用程序的后端收到 504 网关超时错误。
EC2 实例使用 nginx 和 PM2 运行 ubuntu。
/etc/nginx/sites-available
.conf 文件:
server {
listen 80;
server_name mydomain.com;
root /home/ubuntu/app;
index index.html;
access_log /var/log/nginx/app.access.log;
error_log /var/log/nginx/app.error.log;
location / {
try_files $uri /index.html =404;
}
}
server {
listen 8080;
server_name mydomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
我相信我的配置是正确的,因为它可以正常工作,但只能运行几个小时。然后我得到错误。PM2 实例仍然在线并运行。我认为这可能是节点应用程序由于某种原因崩溃了,但是如何在 ubuntu EC2 上解决这个问题?它在我的本地机器上完美运行。
任何建议,将不胜感激。
解决方案
花了几个小时在这上面。事实证明 PM2 和 Nginx 并不总是能很好地协同工作,更改 Nginx 配置并重新启动 Nginx 和 pm2 最终为我解决了这个问题。
具体来说,添加这两行:
proxy_set_header Connection '';
keepalive_timeout 10;
推荐阅读
- android - 从较低 API 中的对话框链接到 Google Play 商店
- jquery - 隐藏/显示工作正常,但幻灯片不工作
- c# - Ef core : 从列表的列表中过滤掉一个项目
- c# - SharePoint CSOM:从 GetChanges() 加载 FileSystemObjectType 属性
- listview - 无法在 ListView 的突出显示中引用内容
- spring - 使用多种配置保护同一端点
- c# - Microsoft Graph 发布操作以创建组“错误请求”
- vuejs2 - 从 nativescript-vue 应用程序中的 js 文件导入字符串
- python - 将列标签格式从日期时间更改为日期
- sql - SQL Server中从位置到位置的子字符串