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://www.aoyou183.cn/wenda/${rc.contextPath}/css/bootstrap.css' rel='stylesheet' type='text/css'/> <!-- font Awesome --> <link href='http://www.aoyou183.cn/wenda/${rc.contextPath}/css/font-awesome.min.css' rel='stylesheet' type='text/css'/> <!-- Ionicons --> <link href='http://www.aoyou183.cn/wenda/${rc.contextPath}/css/ionicons.min.css' rel='stylesheet' type='text/css'/> <!-- Theme style --> <link href='http://www.aoyou183.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 本機(jī)上部署靜態(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. python - 獲取到的數(shù)據(jù)生成新的mysql表2. javascript - js 對中文進(jìn)行MD5加密和python結(jié)果不一樣。3. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat4. window下mysql中文亂碼怎么解決??5. sass - gem install compass 使用淘寶 Ruby 安裝失敗,出現(xiàn) 4046. python - (初學(xué)者)代碼運(yùn)行不起來,求指導(dǎo),謝謝!7. 為啥不用HBuilder?8. python - flask sqlalchemy signals 無法觸發(fā)9. python的文件讀寫問題?10. 為什么python中實例檢查推薦使用isinstance而不是type?
