I have multiple subdomains, all pointing to one machine, and one IP address. On this machine, I want to have nginx acting as a reverse proxy, and depending on which subdomain was used to access the machine, I want it to reverse proxy to a different server. All the examples I've seen of using nginx as a reverse proxy use location, but as I understand that only works for the path, not for different subdomains. How can I achieve what I want?
Asked
Active
Viewed 1.1e+01k times
39
markasoftware
- 509
2 Answers
68
Unless I completely misread your question: You simply set up server blocks for each sub-domain and the define the correct reverse proxy for the root of that subdomain i.e. something along the lines of:
server {
server_name subdomain1.example.com;
location / {
proxy_pass http://hostname1:port1;
}
}
server {
server_name subdomain2.example.com;
location / {
proxy_pass http://hostname2:port2;
}
}
HBruijn
- 84,206
- 24
- 145
- 224