nginx reverse proxy without base url
I have an application that I can't configure a base url.
Let's say that its url is 192.168.1.100:8011
I want to configure the nginx so I can entrer an url like 192.168.1.100/myapp
and it goes to the other app.
The configurations that I'm used to do only work when I have a base url. For example if I have an app on 192.168.1.100:8011/myapp
and I wnat to use nginx for using 192.168.1.100/myapp
, I have no problem but the other way I cant do it.
Is that possible ?
You can use a rewrite rule:
location /myapp/ {
rewrite /myapp(.*) /$1 break;
proxy_pass http://192.168.1.100:8011
}
This will send URLS like /myapp/main/
to the backend as /main/
.
What you probably need is:
location /myapp/ {
proxy_pass http://192.168.1.100:8011/;
}
Notice the trailing slashes on both location and proxy_pass directives.
If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
In this case /myapp/
is being replaced with /