1

My intention is to have several webapps run on different VMs, all put through a nginx proxy.

The main Problem is, that the URL gets changed, e.g. http://example.com/app1/ Gets to the webapp (but CSS doesn't get displayed) and on click on e.g. "login" there is this: http://example.com/login/

So, What I get:

example.com/app1/ -> "click" -> example.com/login/

What I want is:

example.com/app1/ -> "click" -> example.com/app1/login/

The Setup

Virtual Machine redirecting all incoming port 80 traffic to Nginx-VM, Webapp Runs on different VM, hosting own webserver on e.g. port 8000.

File /etc/nginx/sites-enabled/default (abbrev.):

server {
    listen 0.0.0.0:80;
    server_name example.com;
    location /app1/ {
        proxy_pass http://10.11.100.204:8080/;
    }
}

I tried different things, e.g. leaving the trailing slash at the end of the proxy_pass, but that gives me a 404 when calling example.com/app1. proxy_set_header Host $host didn't do the trick either.

Curl output

From Hypervisor Machine (as in comments):

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 3587
Set-Cookie: session=.eJyrVorPTFGyqlZSSFKyUooM98uOCnE0jHIPLfdzcTWMcnGs8s1KrvTNysmOzEo2ijQKrfINdzXwd0m2Va rVUcrJT07MSYVrB2oDCxckpqfGZ2QWl-QXVSpZRStllJQUWOnrF5fmJCbn6-Wm5ZTmF-klZ-grxdYCABkQKVw.B4U2hw.Rbl3k3yxoLQx1UgKpP68uB_X5cI; HttpOnly; Path=/
Server: Werkzeug/0.9.6 Python/2.7.3
Date: Wed, 31 Dec 2014 07:25:59 GMT

From Outside (with external URL example.com/app1/):

HTTP/1.1 200 OK
Server: nginx/1.2.1
Date: Wed, 31 Dec 2014 07:35:06 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 3587
Connection: keep-alive
Set-Cookie: session=.eJyrVorPTFGyqlZSSFKyUorKDTX1C3HL8nPxNPU18suKzI008ctyyojKdTWJDEk38s31LffN8iz3C3G0VarVUcrJT07MSUVodw8FCxckpqfGZ2QWl-QXVSpZRStllJQUWOnrF5fmJCbn6-Wm5ZTmF-klZ1hZGOgrxdYCAHnCKcI.B4U4qg.IWeiafAy-VOV0vhuyUP-dlDFt5w; HttpOnly; Path=/

Without trailing slash "example.com/app1"

HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.1
Date: Wed, 31 Dec 2014 07:29:52 GMT
Content-Type: text/html
Content-Length: 184
Location: http://example.com/app1/
Connection: keep-alive

Thank you in advance!

9
  • Are you sure you are not getting the Location header from browser cache ? If not, what's the result of curl -sI "http://10.11.100.204:8080/" -H "Host: example.com" ? Dec 31, 2014 at 0:49
  • You should configure your apps, so they know that they runs in aubdirectory. But usually it's much easier to use subdomains like app1.example.com, app2.exapmle.com...
    – Alexey Ten
    Dec 31, 2014 at 7:13
  • Curl output added to question.
    – Mat Fluor
    Dec 31, 2014 at 7:25
  • I would suggest trying removing the trailing slash from both the /app1 location setting and the proxy_pass URL. As per the accepted answer to this question; serverfault.com/questions/598003/… Dec 31, 2014 at 7:53
  • Unfortunately removing the trailing slash from the proxy_pass line returns a 404 by the webapp, because it tries to access "/app1" on the VM, but on the VM it's "/".
    – Mat Fluor
    Dec 31, 2014 at 7:59

0

You must log in to answer this question.

Browse other questions tagged .