nginx 解決首頁跳轉問題


 


比如 www.csdn.net 網站后面有 2個tomcat。 
配置負載均衡:

upstream csdn-tomcat{
    server 192.168.100.101:8080; server 192.168.100.102:8080; } server { listen 80; server_name www.csdn.net csdn.net; index index.html; location / { if ( $request_uri = "/" ) { rewrite "/" http://www.csdn.net/index.html break; } proxy_pass http://csdn-tomcat$request_uri; } # 301 redirect: location /blog/index.html { return 301 http://www.iteye.com$request_uri; } }

 

研究好半天,終於解決了。 
首先假設首頁上面是一個靜態的html。 
當用戶沒有直接輸入 www.csdn.net的時候進行 301 跳轉。 
引導用戶到 www.csdn.net/index.html 首頁。 
其他動態請求打到tomcat上面。 
這樣的在nginx上面直接做了301 跳轉。

這樣解決的是問題是由於tomcat 是用spring做的。 
后綴成.html了,沒有辦法區分tomcat 和 普通html了。 
要是tomcat 的后綴成.do就好辦了。

主要是為了減輕 tomcat的壓力。將html css image 都交給nginx去處理。 
但是上線的時候比較麻煩,分開上線。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM