CoopDaddio
CoopDaddio

Reputation: 637

Dynamically proxy to subdomain according to path with nginx?

I am attempting to convert all traffic to its "matching" internal equivalent, and proxy the traffic via this new internal URL.

For example,

I have followed the guide here to attempt to set this up via nginx, however I am receiving the following error:

nginx: [emerg] unknown "path" variable

Below is my nginx configuration file:

server {
  listen 80;
  listen [::]:80;
  
  root /var/www/private/$subdomain;
  
  index index.html index.htm index.nginx-debian.html;
  
  server_name external.com;
  
  location ~ ^/(?<subdomain>[^/]+)/(<path>.*)?$ {
    proxy_pass http://$subdomain.internal.com/$path;
    proxy_buffering off;
    proxy_set_header Host $http_host;
  }
}

Do I need to define the 'path' variable somewhere else? All help is appreciated, thank you.

Upvotes: 1

Views: 843

Answers (1)

palindromeotter33
palindromeotter33

Reputation: 166

You're missing a question mark. It's ?<path> not <path>

Upvotes: 2

Related Questions