我正在使用NGINX服务器作为反向代理。 NGINX服务器接受来自外部客户端的请求(HTTP或HTTPS无关紧要),并将此请求传递给后端服务器。后端服务器向客户端返回“ a” URL,该客户端将具有另一个URL,应使用该URL进行后续的API调用。我希望此返回的URL具有NGIX主机和端口号,而不是后端服务主机和端口号,以便永远不会暴露我的后端服务器详细信息。例如。
1) Client request:
http://nginx_server:8080
2) Nginx receives this and passes it to the backend running with some functionality at
http://backend_server:8090
3) The backend server receives this request and passes another URL to the client http://backend_server:8090/allok.
4) The client uses this URL and makes another subsequent API calls.
我想要的是在响应的第4步中,将“ backend_server:port”替换为初始请求中的nginx服务器和端口。对于例如
http://nginx_server:8080/allok
但是,响应返回为
http://backend_server:8090/allok
我的nginx.conf
http {
server {
listen 8080; --> Client request port
server_name localhost;
location / {
proxy_pass http://localhost:8090; ---> Backend server port. The backend
service and NGINX will always be on the same
machine
proxy_redirect http://localhost:8090 http://localhost:8080; --> Not sure if this is
correct. Doesn't seem to do what I want to achieve
# proxy_set_header Host $host;
}
}
}
预先感谢
答案 0 :(得分:0)
我能够解决它。我不得不从配置中删除proxy_redirect指令。