nginx和tomcat負(fù)載均衡
比如 www.csdn.NET 網(wǎng)站后面有 2個(gè)tomcat。
配置負(fù)載均衡:
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; }}
研究好半天,終于解決了。
首先假設(shè)首頁(yè)上面是一個(gè)靜態(tài)的html。
當(dāng)用戶沒(méi)有直接輸入 www.csdn.Net的時(shí)候進(jìn)行 301 跳轉(zhuǎn)。
引導(dǎo)用戶到 www.csdn.net/index.html 首頁(yè)。
其他動(dòng)態(tài)請(qǐng)求打到tomcat上面。
這樣的在nginx上面直接做了301 跳轉(zhuǎn)。
這樣解決的是問(wèn)題是由于tomcat 是用spring做的。
后綴成.html了,沒(méi)有辦法區(qū)分tomcat 和 普通html了。
要是tomcat 的后綴成.do就好辦了。
主要是為了減輕 tomcat的壓力。將html css image 都交給nginx去處理。
但是上線的時(shí)候比較麻煩,分開(kāi)上線。
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選