title: NGINX Reverse proxy response
body: <p>I am using an NGINX server as a reverse proxy. The NGINX server accepts a request from an external client (HTTP or HTTPS doesn't matter) and passes this request to a backend server. The backend server returns "a" URL to the client that will have another URL that it should use to make subsequent API calls. I want this returned URL to have the NGIX host and port number instead of the backend service host and port number so that my backend server details are never exposed. For e.g.</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>What I want is that in step 4 in the response the "backend_server:port" is replaced by the nginx server and port from the initial request. For e.g</p>
  
  <pre><code>http://nginx_server:8080/allok
  </code></pre>
  
  <p>However, the response goes back as</p>
  
  <pre><code>http://backend_server:8090/allok
  </code></pre>
  
  <p>my nginx.conf</p>
  
  <pre><code>http {
      server {
          listen       8080;     --&gt; Client request port
          server_name  localhost;
  
          location / {         
              proxy_pass http://localhost:8090;   ---&gt; Backend server port. The backend 
                                                       service and NGINX will always be on the same 
                                                       machine
              proxy_redirect http://localhost:8090 http://localhost:8080; --&gt; Not sure if this is 
                                                 correct. Doesn't seem to do what I want to achieve
             # proxy_set_header Host $host;
          }
    }
  }
  </code></pre>
  
  <p>Thanks in advance</p>