Skip to content
The Chat Archive
claude-instant-1· Anthropic Arena Human Preference 55K

Write me an NGINX location block to proxy_pass based on referer value

  1. User

    Write me an NGINX location block to proxy_pass based on referer value

  2. Assistant

    Here is an example NGINX location block that will proxy_pass requests based on the referer value:

    location / {
      if ($http_referer ~* example\.com) {
        proxy_pass http://backend1;
      }
    
      if ($http_referer !~ example\.com) {
        proxy_pass http://backend2;
      }
    }
    

    This will:

    • Check the $http_referer variable for a match to the regex "example.com"
    • If it matches, proxy_pass to backend1
    • If it does not match, proxy_pass to backend2

    The key things:

    • Use the $http_referer variable to check the referer
    • Use if blocks and regex matching/negation to check for specific referer values
    • proxy_pass to different backends based on the referer evaluation

    You can expand on this to have multiple referer checks that proxy to different backends as needed.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.