现在有一个 Web App,监听在本机的 8888 端口,我想把它放到 80 端口的某虚拟目录下,
即通过形如 http://example.com/webapp/
的地址访问。
但是这个 Web App 中静态资源大量使用形如 /static/main.css
的地址,浏览器就会去访问 http://example.com/static/main.css
然后 404,除了把这个 App 反代到根目录和修改 App 代码,有没有什么办法解决这个问题?
1 sampeng 2014-08-20 21:46:53 +08:00 rewrite |
![]() | 2 sandtears OP |
![]() | 3 XiaoxiaoPu 2014-08-20 21:54:30 +08:00 以 Nginx 为例 location /webapp/ { rewrite ^/webapp/(.+)$ /$1 break; proxy_pass http://127.0.0.1:8888; } |
![]() | 4 sandtears OP @XiaoxiaoPu 还是不好用,我的配置文件如下: location /webapp/ { proxy_pass http://127.0.0.1:8888/; proxy_redirect / /webapp/; rewrite ^/(.+)$ /$1 break; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } 其中 proxy_redirect 是为了解决 302 问题,下面三行是为了支持 websocket |
![]() | 5 XiaoxiaoPu 2014-08-20 22:23:53 +08:00 第3行换成"rewrite ^/webapp/(.+)$ /$1 break;"试试? |