簡體   English   中英

Nginx反向代理未將我的http請求發送到在localhost(POST / GET)上運行的服務器

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

我在ec2實例(ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com)上運行節點快遞服務器。 它正在運行一個處理HTTP POST請求的Web服務器,該請求將與RDS數據庫進行交互並返回查詢。

我的目標是例如向端點發送POST / GET請求(ec2-13-229-218-180.ap-southeast-1.compute.amazonaws.com/getData),並使nginx理解並將其轉換為POST / GET請求到http:// localhost:3000 / getData

據我了解,我必須像這樣設置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。 誰能幫我這個? 謝謝。

在服務器塊外部添加以下代碼片段

    upstream nodejs {
        server 127.0.0.1:3000;
}

然后更換

proxy_server http://localhost:3000;

通過

proxy_pass       http://nodejs;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM