Sp4rkR4t
By:
Sp4rkR4t

How can I get nginx to display webapp in *example.com*/here ?

July 29, 2016 681 views
Nginx Server Optimization Ubuntu 16.04

I've built a web app and now I would like to move it to it's own / location on my domain, I thought doing the following would work;

location /here {
proxy_pass http://127.0.0.1:5000:
}

but that doesn't work, if I proxy_pass the app to the / location it works fine.

Any help would be greatly appreciated.

1 comment
  • if I proxy_pass the app to the / location it works fine.
    What do you mean? If it works fine, why not do that?
    And just saying "it doesn't work" doesn't say anything. You need logs, configurations, environment information etc. to give some help..

    Try something like this:

            location \here {
    
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:5000;
    
             }
    
3 Answers
kamaln7 MOD August 2, 2016
Accepted Answer

Hi!

If you rewrite the URL before proxying the request to the backend, it will receive the correct URL while still being served under /here:

location /here {
    rewrite ^/here/(.*)$ /$1 break;
    proxy_pass http://127.0.0.1:5000:
    proxy_redirect    off;
}

What I mean is if a proxy_pass the app at the / location I can view the app fine at my domains address but I dont want that, what I am looking for is have the app be accessible from mydomain.com/HERE.

Have another answer? Share your knowledge.