mrwooster
mrwooster

Reputation: 24207

Extract port number from URL and reverse proxy with Nginx

I would like to setup my Nginx server so

/app/portnum

type URLs are reverse proxied to

localhost:portnum

E.g.

/app/1234

would be reverse proxied to

localhost:1234

Upvotes: 1

Views: 1506

Answers (1)

srain
srain

Reputation: 9082

This may be helpful:

server {
    listen        80;
    server_name       test1.test.com;

    location ~ ^/app/(.*)$ {
        proxy_pass       http://192.168.154.102:$1;
    }
}

Notice: If you visit test1.test.com/app/8081, nginx will pass the request to http://192.168.154.102:8081/app/8081.

More information about proxy_pass

Upvotes: 5

Related Questions