java-ee - nginx反向代理tomcat時資源文件處理問題
問題描述
nginx上配置如下48 location ^~ /bgmonitor/ { 50 proxy_pass http://localhost:8080/; 51 }
形如www.mr.org/bgmonitor的請求轉發到本地8080端口的tomcat
tomcat配置如下<Context docBase='/Users/mr/Documents/code_pool/bgmonitor-git/bgmonitor-web/target/bgmonitor' path='' reloadable='true'/>頁面渲染使用velocity,資源文件引用路徑為:
<!-- bootstrap 3.0.2 --> <link href='http://www.cgvv.com.cn/wenda/${rc.contextPath}/css/bootstrap.css' rel='stylesheet' type='text/css'/> <!-- font Awesome --> <link href='http://www.cgvv.com.cn/wenda/${rc.contextPath}/css/font-awesome.min.css' rel='stylesheet' type='text/css'/> <!-- Ionicons --> <link href='http://www.cgvv.com.cn/wenda/${rc.contextPath}/css/ionicons.min.css' rel='stylesheet' type='text/css'/> <!-- Theme style --> <link href='http://www.cgvv.com.cn/wenda/${rc.contextPath}/css/AdminLTE.css' rel='stylesheet' type='text/css'/>現象
訪問時由于${rc.contextPath}取出為空,導致整個資源路徑變為/css/AdminLTE.css ,這個請求發到nginx后就沒法正常轉發啦
問怎么做才能在最小修改的情況下讓整個應用正常?
問題解答
回答1:靜態文件不需要轉發,在 nginx 本機上部署靜態文件,比如
location ~* ^/(?:images/|js/|css/) { root /home/app/htdocs;}
具體如何配置參考文檔
回答2:詳見博客:http://blog.iaceob.name/nginx-proxy/以及http://blog.iaceob.name/tomcat-multi-domain-binding/
便是我使用的解決方案, 只是我個人這么使用而已, 暫未發現有別人這么使用過.
相關文章:
