Score:0

Nginx proxy using domain as part of url path

cn flag

I'd like to proxy foo.domain.com to the internal server http://localhost:8080/foo, the subdomain part is dynamic so bar.domain.com is also proxy to http://localhost:8080/bar.

I try this code up and running with redirect.

server {
    listen 80;
    server_name ~^(?<subdomain>.+)\.domain\.com$;
    return 301 http://localhost:8080/$subdomain$request_uri;
}

However, I can't really find the solution using a proxy. I tried this but return 502.

server {
    listen 80;
    server_name ~^(?<subdomain>.+)\.domain\.com$;
    
    location / {
        proxy_pass http://localhost:8080/$subdomain;
        # proxy_pass http://localhost:8080/$subdomain$request_uri; # this also not working
    }
}

Any help is really appreciated.

Richard Smith avatar
jp flag
What does the error log say?
djdomi avatar
za flag
is the domain always the same? afaik server_name does not use regex
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.