一、(Tomcat+Nginx)动静分离
1、单机反向代理

利用 nginx 反向代理实现全部转发至指定同一个虚拟主机

客户端curl www.a.com 访问nginx服务,nginx服务通过配置反向代理proxy_pass www.a.com:8080,最终客户端看到的是www.a.com
**实验中:**7-3 做客户机,7-2做代理服务器,7-1 tomcat 服务器 数据传输从7-3到7-2到7-1
7-0参考tomcat虚拟主机配置
①7-1做代理服务器配置
[root@localhost ~]#systemctl stop firewalld ###关闭防火墙
[root@localhost ~]#setenforce 0 ###关闭核心防护
[root@localhost ~]#yum -y install epel-release.noarch ###安装额外源
[root@localhost ~]#yum -y install nginx ###yum安装nginx
[root@localhost ~]#systemctl start nginx ###开启nginx服务
[root@localhost ~]#systemctl status nginx ###查看nginx服务状态
[root@localhost ~]#vim /etc/nginx/nginx.conf ###配置nginx服务主配置文件
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ###开启ip透传
location / {
proxy_pass http://www.b.com:8080; ###访问根就跳转到www.b.com
}
[root@localhost ~]#vim /etc/hosts ###添加域名
192.168.10.100 www.lucky.com www.a.com www.b.com www.c.com
[root@localhost ~]#systemctl restart nginx ###重启nginx服务


进入/etc/nginx/nginx.conf编辑


7-2客户机配置
[root@localhost ~]#systemctl stop firewalld ###关闭防火墙
[root@localhost ~]#setenforce 0 ###关闭核心防护
[root@localhost ~]#yum -y install epel-release.noarch ###安装额外源
[root@localhost ~]#yum -y install nginx ###yum安装nginx
[root@localhost ~]#systemctl start nginx ###开启nginx服务
[root@localhost ~]#systemctl status nginx ###查看nginx服务状态
[root@localhost ~]#vim /etc/hosts ###添加域名
192.168.10.101 www.lucky.com www.a.com www.b.com www.c.com
[root@localhost ~]#systemctl restart nginx ###重启nginx服务
[root@localhost ~]#curl www.a.com
web2 www.b.com
[root@localhost ~]#curl www.b.com
web2 www.b.com
[root@localhost ~]#curl www.c.com
web2 www.b.com
配置:




2、反向代理多机器

3台机器同时关闭防火墙、防护
①7-0 nginx代理服务器配置