nginx和tomcat搭配使用,让nginx可以访问tomcat下面的静态资源
轉載于:http://blog.csdn.net/cxm19881208/article/details/65441865
我們現在開發的一個網站,用的還是比較老的技術,使用jsp開發的,部署在tomcat下面,然后使用nginx做反向代理,配置的時候遇到一個問題,就是瀏覽器訪問的時候只有一些頁面元素,一些css、js、圖片這些靜態資源都沒有加載出來,后來找了很多資料,做出如下配置:
server {
? ? ? ? listen ? ? ? 443;
? ? ? ? server_name? doc.wlyl.com;
? ? ? ? location /yiliao_doc/ {
? ? ? ? ? ? ? ? proxy_pass http://192.168.9.12:8081;
? ? ? ? ? ? ? ? proxy_redirect off ;
? ? ? ? ? ? ? ? proxy_set_header Host $host;
? ? ? ? ? ? ? ? proxy_set_header? X-Real-IP? $remote_addr;
? ? ? ? ? ? ? ? proxy_set_header? X-Forwarded-For $proxy_add_x_forwarded_for;
? ? ? ? ? ? ? ? proxy_set_header X-Forwarded-Proto? $scheme;
? ? ? ? ? ? ? ? proxy_next_upstream error timeout invalid_header;
? ? ? ? }
? ? ? ? location ~ .*\.(html|htm|ico|png|jpg|jpeg|js|css|bmp)$ {
? ? ? ? ? ? proxy_pass http://192.168.9.12:8081;
?? ? ? }
? ? }
注意:location通過正則表達式來配置可以訪問靜態資源,通過正則表達式配置location,里面的proxy_pass一定不能有uri,
即配置成:proxy_pass http://192.168.9.12:8081/;
或者
proxy_pass http://192.168.9.12:8081/yiliao_doc;
都是錯的~
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!
總結
以上是生活随笔為你收集整理的nginx和tomcat搭配使用,让nginx可以访问tomcat下面的静态资源的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt文档阅读笔记-Button QML
- 下一篇: Qt工作笔记-自定义开关控件