Answers: <p>You do not need to use <code>rewrite</code> for your case, since you want to append <code>_plugin/kibana</code> to <strong>any routes</strong>.</p>
  <p>Assuming the nginx config is for <code>http://origin.com/</code>:</p>
  <pre><code>server {
      listen 80;
      server_name origin.com;
      location / {
          proxy_set_header X-Forwared-Proto $scheme;
  
          # http://origin.com/req/1/2 will go to http://target.com/_plugin/kibana/req/1/2
          proxy_pass http://target.com/_plugin/kibana;
  
      }
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-11-10T08:09:43.330Z
Answers: 2020-11-10T08:09:43.330Z
Answers: Lawrence Choy
Body: <p>I want to proxy requests with nginx to different domain and also rewrite some part of the path. For example</p>
  <p><code>http://origin.com/</code> - &gt; <code>http://target.com/_plugin/kibana</code></p>
  <p>How to accomplish such automated addition of <code>_plugin/kibana</code> part to any route that I request and forward to my target server</p>
  <pre><code>server {
      listen 80;
      server_name _;
      location / {
          proxy_set_header X-Forwared-Proto $scheme;
          rewrite ^(.*)$ /_plugin/kibana/$1 break;
          proxy_pass https://my-es-custer-in4lf3ruqx6shv2ndhju.us-east-1.es.amazonaws.com/;
  
      }
  }
  </code></pre>
  <p>Should I have different location blocks or should I have a rewrite directive on a server level for this to work properly?</p>
  
Tags: <amazon-web-services><nginx><kibana>
Title: nginx rewrite with proxy_pass
UserDisplayName: Most Wanted
ThreadText: # nginx rewrite with proxy_pass
  
  (Asked by: username_0 on 2020-11-05)
  
  I want to proxy requests with nginx to different domain and also rewrite some part of the path. For example
  
  `http://origin.com/` - > `http://target.com/_plugin/kibana`
  
  How to accomplish such automated addition of `_plugin/kibana` part to any route that I request and forward to my target server
  
  ```
  server {
      listen 80;
      server_name _;
      location / {
          proxy_set_header X-Forwared-Proto $scheme;
          rewrite ^(.*)$ /_plugin/kibana/$1 break;
          proxy_pass https://my-es-custer-in4lf3ruqx6shv2ndhju.us-east-1.es.amazonaws.com/;
  
      }
  }
  
  ```
  
  Should I have different location blocks or should I have a rewrite directive on a server level for this to work properly?
  
  **Tags:** amazon-web-services, nginx, kibana
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-10. Score: 1 | Accepted answer
  
  You do not need to use `rewrite` for your case, since you want to append `_plugin/kibana` to **any routes**.
  
  Assuming the nginx config is for `http://origin.com/`:
  
  ```
  server {
      listen 80;
      server_name origin.com;
      location / {
          proxy_set_header X-Forwared-Proto $scheme;
  
          # http://origin.com/req/1/2 will go to http://target.com/_plugin/kibana/req/1/2
          proxy_pass http://target.com/_plugin/kibana;
  
      }
  }
  
  ```
  
  
  ---
  
  