How to setup a reverse proxy using nginx?

Solution 1:

I'm not sure this is the correct syntax. Try something like that:

upstream myupstream {
    server 127.0.0.1:8080 fail_timeout=2s;
    keepalive 32;
}

location / {
     proxy_pass http://myupstream;
     proxy_redirect http://myupstream/ /;
}

something along these lines..

But if you just want to redirect port 8080 to 80 why not use a network utility like socat?

Then you should add virtualhosts in nginx for each upstream, and add those virtualhosts in DNS or /etc/hosts, which will all resolve to localhost.

Or you can just avoid the upstream and use virtualhosts like so:

server {
  listen 80;
  server_name myvirtualhost1.local;
  location / {
    proxy_pass http://127.0.0.1:8080;
}

server {
  listen 80;
  server_name myvirtualhost2.local;
  location / {
    proxy_pass http://127.0.0.1:9090;
}