動(dòng)靜分離:
訪問(wèn)靜態(tài)頁(yè)面和動(dòng)態(tài)頁(yè)面分開
實(shí)現(xiàn)動(dòng)態(tài)和靜態(tài)頁(yè)面負(fù)載均衡
實(shí)驗(yàn)5臺(tái)虛擬機(jī)
一、動(dòng)態(tài)負(fù)載均衡
3臺(tái)虛擬機(jī)模擬:
代理服務(wù)器:30
tomcat動(dòng)態(tài)頁(yè)面:21、22
代理服務(wù)器:
??proxy_pass http://tomcat;
????????proxy_set_header HOST $host;
????????proxy_set_header X-Real-IP $remote_addr;
????????proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
進(jìn)html/index.html配置前端頁(yè)面
tomcat后端服務(wù)器:
tomcat:兩個(gè)都進(jìn)入webapps 創(chuàng)建test目錄,在下面創(chuàng)建index.jsp文件
cd /usr/local/tomcat/webapps
mkdir test
cd test
touch index.jsp
輸入:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("動(dòng)態(tài)頁(yè)面1,http://www.test1.com");%>
</body>
</html>
更改server.xml:
148自帶host刪除
最后幾行host更改:(復(fù)制進(jìn)去要看有沒有自動(dòng)換行什么的)
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
????????<Context docBase="/usr/local/tomcat/webapps/test" path="" reloadable="true" />
??????</Host>
重啟tomcat
訪問(wèn)20.0.0.30/index.jsp文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-717688.html
實(shí)現(xiàn)動(dòng)態(tài)頁(yè)面負(fù)載均衡
二、四層+七層+動(dòng)靜分離
需要5臺(tái)服務(wù)器:
- nginx代理
- 靜態(tài)頁(yè)面請(qǐng)求轉(zhuǎn)發(fā)服務(wù)器
- tomcat服務(wù)器
代理30
tomcat動(dòng)態(tài)21 22
靜態(tài) 23 40
代理服務(wù)器:
下面端口號(hào)要加
下面server中端口也是80,需要改一下
配置2 3nginx靜態(tài)頁(yè)面服務(wù)器
??location ~* \.jsp$ {
?????????proxy_pass http://tomcat;
?????????proxy_set_header HOST $host;
?????????proxy_set_header X-Real-IP $remote_addr;
??????????proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
????????}
配置靜態(tài)頁(yè)面:html/inde.html
代理服務(wù)器的index.html要清空刪除
20.0.0.30:8080請(qǐng)求靜態(tài)
看是否負(fù)載均衡
瀏覽器有時(shí)候做不了負(fù)載均衡,curl 20.0.0.30查看就行
訪問(wèn)20.0.0.30/index.jsp
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-717688.html
到了這里,關(guān)于tomcat的負(fù)載均衡、動(dòng)靜分離(nginx聯(lián)動(dòng))的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!