【问题标题】:Nginx reverse proxy is not sending my http requests to server running on localhost (POST/GET)Nginx 反向代理没有将我的 http 请求发送到在本地主机上运行的服务器(POST/GET)
【发布时间】:2018-09-30 19:52:11
【问题描述】:

我在 ec2 实例 (ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com) 上运行节点快速服务器。它正在运行一个 Web 服务器来处理将与 RDS 数据库交互并返回查询的 http POST 请求。

我的目标是向端点发送 POST/GET 请求,例如(ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData),并让 nginx 理解并翻译它到http://localhost:3000/getData 的 POST/GET 请求)

据我了解,我必须像这样设置 nginx 配置:

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

    root /var/www/example.com/html;
    index index.html index.htm index.nginx-debian.html;

    server_name ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com;

    location / {

            proxy_server http://localhost:3000;                                                    
            //other stuff
    }

}

Nginx 能够以当前配置运行,但是当我尝试测试向 ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData 发送发布请求时,我得到404。谁能帮我这个?谢谢。

【问题讨论】:

    标签: amazon-web-services express nginx amazon-ec2


    【解决方案1】:

    在服务器块外添加下面的代码sn-p

        upstream nodejs {
            server 127.0.0.1:3000;
    }
    

    然后替换

    proxy_server http://localhost:3000;
    

    proxy_pass       http://nodejs;
    

    【讨论】:

      猜你喜欢
      • 2017-02-14
      • 2014-07-08
      • 2017-01-28
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多