title: How to make nginx redirect to a different port
body: <p>I have the following location block in the nginx.conf file.</p>
  
  <pre><code>Location /e-ui/ {
      proxy_pass https://hostname:9000
  }
  </code></pre>
  
  <p>I need to know how I can redirect sites in the following manner:</p>
  
  <p><a href="https://abc/e-ui/" rel="nofollow noreferrer">https://abc/e-ui/</a> should be redirected to <a href="https://abc:9000" rel="nofollow noreferrer">https://abc:9000</a></p>
  
  <p>OR</p>
  
  <p><a href="https://xyz/e-ui/" rel="nofollow noreferrer">https://xyz/e-ui/</a> should be redirected to <a href="https://xyz:9000" rel="nofollow noreferrer">https://xyz:9000</a></p>
  
  <p>The server name is changing ( as the code is deployed on many servers ). Is there anyway I can get the server name from the /etc/hosts file if it is already defined there and use it somehow to redirect the sites as mentioned above ?</p>
  
  <p>Thank you.</p>