Regular expression from the hostname in the proxy_pass uri in Nginx

Solution 1:

Untested, but give this a shot:

server_name   ~^(www\.)?[^.]+.example.org$;

if ($host ~* ^(www\.)?([^.]+).example.org$) {
    set $subdomain $2;
}

location / {
    proxy_pass http://example.org:8080/$subdomain;
}