简体   繁体   English

Nginx反向代理未将我的http请求发送到在localhost(POST / GET)上运行的服务器

[英]Nginx reverse proxy is not sending my http requests to server running on localhost (POST/GET)

I'm running a node express server on an ec2 instance (ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com). 我在ec2实例(ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com)上运行节点快递服务器。 It is running a web server that handles http POST requests that will interact with an RDS database, returning queries. 它正在运行一个处理HTTP POST请求的Web服务器,该请求将与RDS数据库进行交互并返回查询。

My goal is to have POST/GET requests to the endpoints for example (ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData), and have nginx understand and translate that to a POST/GET request to http://localhost:3000/getData ) 我的目标是例如向端点发送POST / GET请求(ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData),并使nginx理解并将其转换为POST / GET请求到http:// localhost:3000 / getData

From my understanding, I have to setup the nginx configuration like so: 据我了解,我必须像这样设置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 is able to run with the current configuration, but when I try to test sending post requests to ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData , i'm getting 404's. Nginx可以使用当前配置运行,但是当我尝试测试将发帖请求发送到ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData时,我得到了404。 Can anyone help me with this? 谁能帮我这个? Thanks. 谢谢。

Add below code snippet outside the server block 在服务器块外部添加以下代码片段

    upstream nodejs {
        server 127.0.0.1:3000;
}

Then replace 然后更换

proxy_server http://localhost:3000;

by 通过

proxy_pass       http://nodejs;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 nginx反向代理到本地主机 - nginx reverse proxy to localhost 在使用 CloudFront CDN 处理 GET 请求时,我可以反向代理 POST 请求吗? - Can I reverse-proxy POST requests while using CloudFront CDN for GET requests? 不同服务器的 Elasticbeanstalk Nginx 反向代理配置 - Elasticbeanstalk Nginx Reverse Proxy Conf for Different Server NGINX配置以将SSL请求代理到Sinatra服务器 - NGINX configuartion to proxy SSL requests to a Sinatra server 如何让Elastic Beanstalk nginx支持的代理服务器从HTTP自动重定向到HTTPS? - How to get Elastic Beanstalk nginx-backed proxy server to auto-redirect from HTTP to HTTPS? 在Beanstalk上运行的PHP-App的nginx http-proxy infront - nginx http-proxy infront of PHP-App running on Beanstalk 在AWS实例中设置反向代理,运行Tomcat服务器 - Setting reverse proxy in aws instance, running tomcat server Django 落后于 NGINX 反向代理和 AWS Application Load Balancer 未在 HTTP_X_FORWARDED_PROTO 中从客户端转发 HTTPS - Django behind NGINX reverse proxy and AWS Application Load Balancer doesn't get HTTPS forwarded from client in HTTP_X_FORWARDED_PROTO AmazonCloudWatchClient不发送HTTP请求 - AmazonCloudWatchClient not sending HTTP requests 了解服务器架构:使用 Nginx 反向代理或 Apache 服务器从 AWS S3 传送内容 - Understanding server architecture: Delivering content from AWS S3 using Nginx reverse-proxy or Apache server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM