title: Combining Nginx location blocks.
body: <p>I have the following config in nginx conf</p>
  
  <pre><code>location /request1 {
            proxy_pass  http://hostname:port/request1;
            proxy_set_header Host      $host;
            proxy_set_header X-Real-IP $remote_addr;
  }
  
  location /request2 {
            proxy_pass  http://hostname:port/request2;
            proxy_set_header Host      $host;
            proxy_set_header X-Real-IP $remote_addr;
  }
  
  location /request3 {
            proxy_pass  http://hostname:port/request3;
            proxy_set_header Host      $host;
            proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>
  
  <p>I want to merge them into one config like </p>
  
  <pre><code>location ~ /(request1|request2|request3)/ {
            proxy_pass  http://hostname:port/$1;
            proxy_set_header Host      $host;
            proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>
  
  <p>I could not figure out the syntax. Anyone can help me out? </p>
  
  <p><strong>Answer to my question:</strong></p>
  
  <p>The following works for me: </p>
  
  <pre><code>location ~ ^/(request1|request2|request3) {
      proxy_pass  http://hostname:port;
      proxy_set_header Host      $host;
      proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>