我的意图是有几个webapps在不同的虚拟机上运行,都通过一个nginx代理。
主要的问题是,url被改变,例如http://example.com/app1/获取到web应用程序(但CSS不显示),并点击例如“login”有这样的: http://example.com/login/
那么,我得到了什么:
example.com/app1/ -> "click" -> example.com/login/
我想要的是:
example.com/app1/ -> "click" -> example.com/app1/login/
安装程序
虚拟机将所有传入的端口80stream量redirect到Nginx-VM,Webapp在不同的虚拟机上运行,在端口8000上托pipe自己的networking服务器。
文件/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/; } }
我尝试了不同的东西,例如在proxy_pass的末尾留下了斜线,但是在调用example.com/app1时给了我一个404。 proxy_set_header Host $host也没有这个把戏。
curl输出
来自Hypervisor机器(如评论):
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
来自外部(使用外部urlexample.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=/
没有结尾斜杠“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
先谢谢你!