1

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
1
  • can you URL's be longer, something like /app/port/some/extra/uri ? Commented Sep 11, 2013 at 8:11

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, managed to work it out... I had to use re-write as well. I couldnt find the documentation anywhere which showed you could use regex groups in the location command. Thx
Yes it work but how to remove port in url, to proxy_path, must use rewrite ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.