linux虚拟机安装nginx+反向代理+负载均衡
AI-摘要
切换
Tianli GPT
AI初始化中...
介绍自己 🙈
生成本文简介 👋
推荐相关文章 📖
前往主页 🏠
前往爱发电购买
linux虚拟机安装nginx+反向代理+负载均衡
REAIlinux虚拟机安装nginx+反向代理+负载均衡
安装nginx
c++编译环境
1  | yum install gcc-c++ //安装c++编译环境  | 
模块依赖库
1  | yum -y install pcre* openssl* zlib* //安装模块依赖库  | 
下载
1  | wget http://nginx.org/download/nginx-1.21.3.tar.gz  | 
解压 /usr/local
1  | tar -zxvf nginx-1.21.3.tar.gz -C /usr/local  | 
在/usr/local下生成一个nginx目录
1  | cd /usr/local/nginx-1.21.3  | 
启动
1  | cd /usr/local/nginx/sbin/  | 
关闭
1  | cd /usr/local/nginx/sbin  | 
重启
1  | //重新加载配置文件  | 
反向代理
反向代理qwer.top 到 127.0.0.1:8080
修改本地 hosts 文件,将qwer.top 映射到 127.0.0.1
1  | vim /etc/hosts  | 
访问:qwe.top:8080
配置nginx.conf
vim /usr/local/nginx/conf/nginx.conf
1  | server {  | 
访问:qwer.top
1  | listen *:80 | *:8080 #监听所有80端口和8080端口  | 
负载均衡
同时启动两个tomcat:tomcat1、tomcat2
特别要注意:不要设置CATALINA_HOME
分别修改安装目录下的conf子目录中的server.xml文件:
a.修改tomcat1   http访问端口 vim ./tomcat1/conf/server.xml
1  | <Server port="8095" shutdown="SHUTDOWN">  | 
1  | <Connector port="8091" protocol="HTTP/1.1"  | 
修改tomcat2   http访问端口 vim ./tomcat2/conf/server.xml
1  | <Server port="8096" shutdown="SHUTDOWN">  | 
1  | <Connector port="8092" protocol="HTTP/1.1"  | 
启动tomcat
./tomcat1/bin/startup.sh
./tomcat2/bin/startup.sh
访问
127.0.0.1:8091
127.0.0.1:8092
实现普通轮询
配置文件nginx.conf  /usr/local/nginx/conf/
1  | 
  | 
weight权重 默认为1
启动nginx
1  | cd /usr/local/nginx/sbin/  | 
访问
qwer.top
 评论
匿名评论隐私政策



