Ok I can't seem to get it, I've checked nginx forum, not much help there either. I thought this would be simple. I want defined subdomains to go to a different url/port. i.e.
DNS site.com goes to 192.168.1.1 w/ masking
DNS www.site.com goes 192.168.1.1 w/ masking
DNS red.site.com goes 192.168.1.1 w/ masking
DNS blue.site.com goes to 192.168.1.1 w/ masking
I want site.com and www.site.com to function as normal, but I want red.site.com to go to 192.168.1.2:5000 and blue.site.com to go to 192.168.1.2:6000/temp/
etc, etc....I'm not even sure I care what displays in the address bar, I guess it would be nice if it stayed red.site.com, but it's not important. I've tried a proxy pass a url rewrite, clearly I am doing something wrong. Is this even possible?
Have you tried the Proxy pass directive?
With something like
server {
server_name red.site.com;
location / {
proxy_pass http://192.168.1.2:5000;
}
}
server {
server_name blue.site.com;
location / {
proxy_pass 192.168.1.2:6000/temp/;
}
}
should work. Look at the documentation for things like header to forward etc...
Create as many virtual servers as you need. Check in /etc/nginx/sites-available and copy the default server to red ... (or where your config here). Then go to /etc/nginx/sites-enabled and do a symlink
ln -s ../sites-available/red
and do the same for other servers (blue...), then restart nginx or killall -HUP nginx to reload the config.
Basically in a virtual server you give whatever configuration is specific to that server.
For instance, for red
server {
listen 5000;
server_name red.site.com;
root /var/www/docs/red;
...
}
or for blue (notice the temp added to root)
server {
listen 6000;
server_name blue.site.com;
root /var/www/docs/somewhere/temp;
...
}
If you need to specify the IP as well, do
listen 192.168.1.2:5000;
for red, or 6000 for blue.
Some litterature that explains the directives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With