I am trying to set up host and port remapping on Linux using nginx as a reverse proxy.
So far, I've got a working ghetto hack solution using the if
directive, which is evil.
Is there a better solution without using if
?
What I have tried - nginx configuration
/etc/nginx/nginx.conf (or some /etc/nginx/conf.d/*.conf file):
server {
listen 3000;
server_name dev.example.com test.example.com prod.example.com
location / {
if ($http_host ~ dev.example.com) {
proxy_pass 127.0.0.1:13000;
}
if ($http_host ~ test.example.com) {
proxy_pass 127.0.0.1:23000;
}
if ($http_host ~ prod.example.com) {
proxy_pass 127.0.0.1:33000;
}
}
}
/etc/hosts:
127.0.0.1 dev.example.com
127.0.0.1 test.example.com
127.0.0.1 prod.example.com
What I would like to do - Fiddler HOSTS configuration
For those familiar with Fiddler, I am trying to emulate this HOSTS configuration:
localhost:13000 dev.example.com:3000
localhost:23000 test.example.com:3000
localhost:33000 prod.example.com:3000