Kir
Kir

Reputation: 3052

NGINX reverse proxy to a host with no root subdirectory

Usually, when doing a reverse proxy setup, you have a server on your backend which looks like this:

http://localhost:8084/app-root

and you can proxy_pass

location /app-root { proxy_pass http://localhost:8084; }

It will proxy www.my-domain.com/app-root to the internal server http://localhost:8084/app-root.

Great!

Can someone explain what needs to be done if the server insists on hosting from the root as so:

http://localhost:8084/index.html http://localhost:8084/images/image1.jpg

I want this to be accessible via

http://www.my-domain.com/app/index.html
http://www.my-domain.com/app/images/image1.jpg

Upvotes: 2

Views: 5574

Answers (1)

Bipul Jain
Bipul Jain

Reputation: 4643

You can use rewrite of nginx. Something like this should work

location  /app/ {
  rewrite /app/(.*) /$1  break;
  proxy_pass         http://localhost:8084;
}

Upvotes: 3

Related Questions