title: conditional routing with nginx based on referer
body: <p>I need to route traffic based on the http request origin. I have two environments and we need to redirect every http request for "/us-en" to Environment1 and others to Environment2 using "$http_referer".</p>
  
  <ol>
  <li>Redirection based on location works.</li>
  </ol>
  
  <pre><code>location ~ /us-en { 
      proxy_pass Environment1; 
      proxy_set_header Host Environment1; 
  } 
  </code></pre>
  
  <ol start="2">
  <li>With '$http_referer' the below option does not work. Request your suggestion on the same. </li>
  </ol>
  
  <pre><code>if ($http_referer ~ ^https?://dev.xyz.com/us-en){ 
      rewrite ^/us-en(/*)$ HOME_PAGE$1 break; 
      proxy_pass Environment1; 
  }
  Error: nginx: [emerg] "proxy_pass" directive is not allowed here in /opt/nginx/conf/nginx.conf.
  </code></pre>
  
  <p>Note: By default all the traffic goes to Environment2 as an upstream configuration is present.</p>