java-ee - nginx反向代理tomcat時資源文件處理問題
問題描述
nginx上配置如下48 location ^~ /bgmonitor/ { 50 proxy_pass http://localhost:8080/; 51 }
形如www.mr.org/bgmonitor的請求轉(zhuǎn)發(fā)到本地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://m.4tl426be.cn/wenda/${rc.contextPath}/css/bootstrap.css' rel='stylesheet' type='text/css'/> <!-- font Awesome --> <link href='http://m.4tl426be.cn/wenda/${rc.contextPath}/css/font-awesome.min.css' rel='stylesheet' type='text/css'/> <!-- Ionicons --> <link href='http://m.4tl426be.cn/wenda/${rc.contextPath}/css/ionicons.min.css' rel='stylesheet' type='text/css'/> <!-- Theme style --> <link href='http://m.4tl426be.cn/wenda/${rc.contextPath}/css/AdminLTE.css' rel='stylesheet' type='text/css'/>現(xiàn)象
訪問時由于${rc.contextPath}取出為空,導(dǎo)致整個資源路徑變?yōu)?css/AdminLTE.css ,這個請求發(fā)到nginx后就沒法正常轉(zhuǎn)發(fā)啦
問怎么做才能在最小修改的情況下讓整個應(yīng)用正常?
問題解答
回答1:靜態(tài)文件不需要轉(zhuǎn)發(fā),在 nginx 本機上部署靜態(tài)文件,比如
location ~* ^/(?:images/|js/|css/) { root /home/app/htdocs;}
具體如何配置參考文檔
回答2:詳見博客:http://blog.iaceob.name/nginx-proxy/以及http://blog.iaceob.name/tomcat-multi-domain-binding/
便是我使用的解決方案, 只是我個人這么使用而已, 暫未發(fā)現(xiàn)有別人這么使用過.
相關(guān)文章:
1. html - 微信瀏覽器h5<video>標(biāo)簽問題2. python - 如何對列表中的列表進行頻率統(tǒng)計?3. node.js - 為什么微信的消息MsgId出現(xiàn)重復(fù)了,無法排重了。。4. java - mysql緩存問題5. javascript - 關(guān)于Node 、 commonJs、 vue 之間的故事6. android - 像支付寶到位這種點擊marker點擊變大怎么做的7. javascript - 關(guān)于ios微信端瀏覽器網(wǎng)頁的一些問題8. python - 如何正則字符串中的所有漢字9. android 微信是如何實現(xiàn)即時更新好友頭像的10. 黑客 - Python模塊安全權(quán)限
