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://m.b3g6.com/wenda/${rc.contextPath}/css/bootstrap.css' rel='stylesheet' type='text/css'/> <!-- font Awesome --> <link href='http://m.b3g6.com/wenda/${rc.contextPath}/css/font-awesome.min.css' rel='stylesheet' type='text/css'/> <!-- Ionicons --> <link href='http://m.b3g6.com/wenda/${rc.contextPath}/css/ionicons.min.css' rel='stylesheet' type='text/css'/> <!-- Theme style --> <link href='http://m.b3g6.com/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/
便是我使用的解決方案, 只是我個人這么使用而已, 暫未發現有別人這么使用過.
相關文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關于進程間發送句柄的一點疑問5. Apache 已經把網站根目錄的改為allow from all了,但是服務器還是不能訪問?6. 實現bing搜索工具urlAPI提交7. 配置Apache時,添加對PHP的支持時語法錯誤8. vue.js - Vue 如何像Angular.js watch 一樣監聽數據變化9. javascript - 移動端上不能實現拖拽布局嗎?10. phpstudy8.1支持win11系統嗎?

網公網安備