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.4tl426be.cn/wenda/${rc.contextPath}/css/bootstrap.css' rel='stylesheet' type='text/css'/> <!-- font Awesome --> <link href='http://www.4tl426be.cn/wenda/${rc.contextPath}/css/font-awesome.min.css' rel='stylesheet' type='text/css'/> <!-- Ionicons --> <link href='http://www.4tl426be.cn/wenda/${rc.contextPath}/css/ionicons.min.css' rel='stylesheet' type='text/css'/> <!-- Theme style --> <link href='http://www.4tl426be.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/
便是我使用的解決方案, 只是我個人這么使用而已, 暫未發現有別人這么使用過.
相關文章:
1. 數組按鍵值封裝!2. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題3. docker不顯示端口映射呢?4. python - flask _sqlalchemy 能否用中文作為索引條件5. python3.x - git bash如何運行.bat文件?6. java - 阿里的開發手冊中為什么禁用map來作為查詢的接受類?7. javascript - ES6規范下 repeat 函數報錯 Invalid count value8. html5 - 使用echarts中的圖表 一個頁面導入了好幾個js圖表 實現echarts圖表隨著瀏覽器窗口變化而變化時出現了問題9. javascript - webpack中alias配置中的“@”是什么意思?10. javascript - 為什么創建多行多列的表格最后只有一行內有表格
