【问题标题】:Unable to figure out 504 error in NodeJS running on NGINX Web Server on AWS在 AWS 上的 NGINX Web 服务器上运行的 NodeJS 中无法找出 504 错误
【发布时间】:2020-06-02 16:05:04
【问题描述】:

当我按顺序向 Facebook、Google 等 3rd 方 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.js amazon-web-services nginx post request


    【解决方案1】:

    我相信您在 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;
      }
    }
    

    【讨论】:

    • 我在sites-enabled文件夹的配置文件中有服务器块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    相关资源
    最近更新 更多