Home > Software engineering >  Dynamically proxy to subdomain according to path with nginx?
Dynamically proxy to subdomain according to path with nginx?

Time:09-10

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.

CodePudding user response:

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

  • Related