【问题标题】:NGINX Reverse proxy responseNGINX 反向代理响应
【发布时间】: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;
        }
  }
}

提前致谢

【问题讨论】:

    标签: nginx proxy


    【解决方案1】:

    我能够解决它。我不得不从配置中删除 proxy_redirect 指令。

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-05
      • 2020-11-28
      • 2011-08-09
      • 2013-02-18
      • 2021-04-08
      相关资源
      最近更新 更多