nginx和tomcat負載均衡
比如 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去處理。
但是上線的時候比較麻煩,分開上線。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答