
standalone模式,Tomcat单独运行,直接接受用户的请求,不推荐。
反向代理,单机运行,提供了一个Nginx作为反向代理,可以做到静态由nginx提供响应,动态jsp代理给Tomcat
LNMT:Linux + Nginx + MySQL + Tomcat
LAMT:Linux + Apache(Httpd)+ MySQL + Tomcat
前置一台Nginx,给多台Tomcat实例做反向代理和负载均衡调度,Tomcat上部署的纯动态页面更适合
LNMT:Linux + Nginx + MySQL + Tomcat
多级代理
LNNMT:Linux + Nginx + Nginx + MySQL + Tomcat利用 nginx 反向代理实现全部转发置指定同一个虚拟主机
利用nginx反向代理功能,将3.5.1中图(2)的代理功能,将用户请求全部转发至指定的同一个虚拟主机
从epel源安装nginx
# yum install nginx -y
# vim /etc/nginx/nginx.conf
# 全部反向代理测试
location / {
# proxy_pass http://127.0.0.1:8080; # 不管什么请求,都会访问后面的localhost虚拟主机
proxy_pass http://node1.magedu.com:8080; # 此项将用户访问全部请求转发到node1的虚拟主机上
#proxy_pass http://node2.magedu.com:8080; #此项将用户访问全部请求转发到node2的虚拟主机上
#以上两项都需要修改nginx服务器的/etc/hosts
}
# nginx -t
#systemctl restart nginx
范例:
#先按3.4.5.4介绍方式建立两个tomcat虚拟主机,node1.magedu.org和node2.magedu.org
#修改/etc/hosts文件,实现名称解析
[root@centos8 ~]#vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos8.localdomain
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.8 node1.magedu.org node2.magedu.org
#基于EPEL安装nginx
[root@centos8 ~]#yum -y install nginx
#修改nginx.conf配置文件
[root@centos8 ~]#vim /etc/nginx/nginx.conf
......
#修改location / 行,添加以下内容
location / {
#proxy_pass http://127.0.0.1:8080;
proxy_pass http://node1.magedu.org:8080; }
......
[root@centos8 ~]#systemctl restart nginx
#先别访问node1,node2和IP都可以看到一样的node1的虚拟主机页面
[root@centos8 ~]#curl http://node1.magedu.org/
jsp例子
后面的内容是服务器端动态生成字符串,最后拼接在一起
node1.magedu.org
[root@centos8 ~]#curl http://node2.magedu.org/
jsp例子
后面的内容是服务器端动态生成字符串,最后拼接在一起
node1.magedu.org
[root@centos8 ~]#curl http://127.0.0.1/
jsp例子
后面的内容是服务器端动态生成字符串,最后拼接在一起
node1.magedu.org
[root@centos8 ~]#curl http://10.0.0.8/
jsp例子
后面的内容是服务器端动态生成字符串,最后拼接在一起
node1.magedu.org
[root@centos8 ~]#systemctl restart nginx
#再次修改nginx.conf配置文件
[root@centos8 ~]#vim /etc/nginx/nginx.conf
......
#修改location / 行,添加以下内容
location / {
#proxy_pass http://127.0.0.1:8080;
proxy_pass http://node2.magedu.org:8080; }
......
#先别访问node1,node2和IP都可以看到一样的node2的虚拟主机页面
[root@centos8 ~]#curl http://node1.magedu.org/
[root@centos8 ~]#curl http://node2.magedu.org/
[root@centos8 ~]#curl http://127.0.0.1/
[root@centos8 ~]#curl http://10.0.0.8/
[root@centos8 ~]#curl http://10.0.0.8/
jsp例子
后面的内容是服务器端动态生成字符串,最后拼接在一起
node2.magedu.org
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)