Tomcat(二) 动静分离

一、(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代理服务器配置

相关推荐
JuiceFS15 小时前
从 MLPerf Storage v2.0 看 AI 训练中的存储性能与扩展能力
运维·后端
chen94520 小时前
mysql 3节点mgr集群部署
运维·后端
LH_R21 小时前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler1 天前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
少妇的美梦2 天前
logstash教程
运维
chen9452 天前
k8s集群部署vector日志采集器
运维
chen9452 天前
aws ec2部署harbor,使用s3存储
运维
christine-rr2 天前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神5552 天前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆2 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs