Nginx+Tomcat负载均衡及动静分离


一.部署Tomcat
托包(apache-tomcat-8.5.16 、jdk-8u102-linux-x64 、nginx包)

包都在我主页的资源里
在后两台一起
rpm -ivh jdk-8u102-linux-x64.rpm
java -version
tar zxvf apache-tomcat-8.5.16.tar.gz
mv apache-tomcat-8.5.16 /usr/local/tomcat8
cd /usr/local/tomcat8/conf
vim server.xml


mkdir -p /web/webapp

各自
vim /web/webapp/index.jsp

/usr/local/tomcat8/bin/startup.sh
netstat -anpt |grep java
验证  ip:8080

在调度器上(主机上)
yum install -y make gcc gcc-c++  pcre-devel zlib-devel openssl-devel
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-1.12.0.tar.gz -C /usr/src/

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module && make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
二.配置Nginx负载均衡
vim /usr/local/nginx/conf/nginx.conf

三.配置Nginx反向代理
vim /usr/local/nginx/conf/nginx.conf

location ~ .*.jsp$ {
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;            proxy_set_header Client-IP $remote_addr;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            proxy_pass http://tomcat_server;           }


三.配置Nginx动静分离

nginx -t
cd /usr/local/nginx/html/

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>静态页面</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>静态页面</h1>
<p>这是个静态页面</p>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值