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!
Location
header from browser cache ? If not, what's the result ofcurl -sI "http://10.11.100.204:8080/" -H "Host: example.com"
?/app1
location setting and theproxy_pass
URL. As per the accepted answer to this question; serverfault.com/questions/598003/…