Search code examples
angularjsnginxreverse-proxyhaproxyforwarding

Ngnix : Forwarding url to AngularJS webapp


With my AngularJS SPA webapp, I would like to use a Ngnix to forward url from example :

   http://example.com
   http://example.com/#/user/login
   ...

to :

   http://example.com:8080/webappname
   http://example.com:8080/webappname/#/user/login

I tried this configuration :

server {
    listen 80;
    server_name example.com;

    location / {
            proxy_pass http://127.0.0.1:8080/webappname;
    }
}

But it does not work. Thanks for your help.


Solution

  • You need a "/" at the end. Without a URL

    http://example.com/#/user/login
    

    is translated to

    http://example.com:8080/webappname#/user/login
    

    Here's the correct line:

    proxy_pass http://127.0.0.1:8080/webappname/;