【发布时间】:2019-11-14 04:54:35
【问题描述】:
我使用 NGINX 服务器作为反向代理。 NGINX 服务器接受来自外部客户端的请求(HTTP 或 HTTPS 无关紧要)并将该请求传递给后端服务器。后端服务器向客户端返回“一个”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;
}
}
}
提前致谢
【问题讨论】: