Nginx reverse proxy rewrite to hide app name

When you change the content of the URI being processed within a location block containing a proxy_pass directive then you need to handle Location header rewrites with proxy_redirect :

In some cases, the part of a request URI to be replaced cannot be determined:

  • When location is specified using a regular expression. In this case, the directive should be specified without a URI.

  • When the URI is changed inside a proxied location using the rewrite directive, and this same configuration will be used to process a request (break).

But in your case there's no reason to use a rewrite because nginx already handles this in the proxy_pass directive while adding an URI prefix:

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.

Also you need to remove the proxy_redirect directive so nginx can rewrite Location headers using the proxy_pass URI prefix as a pattern and the location prefix as a replacement.

So simply use this :

server {

    server_name sub.domain.com;

    location / {
            proxy_pass http://172.17.1.10:8080/myapp/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            include /etc/nginx/proxy_params;
    }

}

Change these three lines should fix you:

location /myapp {
            rewrite ^/myapp(.*) /$1 break;
            proxy_pass http://172.17.1.10:8080;

To:

location / {
            proxy_pass http://172.17.1.10:8080/myapp;