首页 > 解决方案 > 在 AWS 上的 NGINX Web 服务器上运行的 NodeJS 中无法找出 504 错误

问题描述

当我按顺序向 Facebook、Google 等第三方 API 发出 POST 请求时,我随机收到 504 错误。我无法确定导致错误的确切情况。

这是我发出 POST 请求的方式:

 var options = { uri: uri,
                 headers: {
                   "Content-Type": "application/json",
                 },
                 strictSSL: true,
                 json: obj
               }; 


 request.post(options, function(err, response) {


 });

这是我的 NGINX 配置文件:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
 worker_connections  1024;
}


http {

  client_max_body_size 100M;
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

  access_log  /var/log/nginx/access.log  main;

  sendfile        on;


  keepalive_timeout  65;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;


}

我在 AWS 的 2 个 EC2 实例上运行我的应用程序,并附加了一个负载均衡器。

这里可能是什么问题?

标签: node.jsamazon-web-servicesnginxpostrequest

解决方案


我相信您在 http 块内缺少服务器块。使用位置块将客户端重定向到更精细调整的路线,而不仅仅是根

server {
  listen 80;
  listen [::]:80;

  root /home/ubuntu/public_html;

  server_name example-one.com www.example-one.com;

  location /application1 {
      proxy_pass http://localhost:8080/sampleApp;
  }

  location /images {
      root /home/ubuntu/data;
  }
}

推荐阅读