[英]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.