I have an application that I can't configure a base url. Let's say that its url is

I want to configure the nginx so I can entrer an url like 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 and I wnat to use nginx for using, I have no problem but the other way I cant do it.

Is that possible ?

  • Are you good ? does the config below work for you ? Nov 22, 2016 at 20:09
  • are both of these hosted by the same nginx server? Can you post the relevant sections of the nginx config and obscure any personal info so we can help see what the issue/solution may be?
    – SteamerJ
    Dec 18, 2018 at 19:15

4 Answers 4


You can use a rewrite rule:

location /myapp/ {
    rewrite /myapp(.*) /$1 break;

This will send URLS like /myapp/main/ to the backend as /main/.

  • I think I didn't explain myself enough. What I want is to redirect the to Sep 22, 2016 at 21:10
  • 1
    Redirect or reverse proxy? For a reverse proxy this is the solution to map urls /myapp/foo to /foo on the backend. For a redirect, just use a http redirect like described in the nginx docs.
    – allo
    Sep 23, 2016 at 0:12

What you probably need is:

location /myapp/ {

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


In this case /myapp/ is being replaced with /

  • This was definitely the best one in my case; the tiny detail there with the trailing / allowed me for the removal of all kinds of annoying regular expression magic I had before. Reading the manual actually helps?!?
    – CharlesS
    Feb 25 at 10:56

Here is what I did to redirect http://example.com/app to (example.com/app being the WAN address and being the LAN address)

location /app/ {
    proxy_redirect http://example.com/app/;

    proxy_set_header Host $host;
    proxy_set_header Referer $http_referer;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
  • you may want to use the default server and a location block then you wont need a url as it will catch any names to thw default server
    – djdomi
    Apr 19, 2020 at 21:14
  • @djdomi What would that look like?
    – uranibaba
    Apr 22, 2020 at 9:07

Is it okay to be taken away from /myapp (by the browser)?

That is simple:

location /myapp  { return 303; }
location /myapp/ { return 303; }

Do you want to keep deeper requests like /myapp/blah.txt?

location ~ ^/myapp(?<myslash>/|$)(?<mypath>.*)$
    set $myargs $args;  # workaround allowing spaces
    return 303$myslash$mypath$is_args$myargs;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.