一 准备条件
三台虚拟机
nginx 192.168.137.5
Tomcat 192.168.137.6
Tomcat 192.168.137.7
配置 IP hostname 关闭防火墙
其中两台启动tomcat 部署项目
第三台安装nginx
安装nginx:
1: 安装:缺少GCC编辑器:
yum -y install pcre*
yum -y install openssl*
yum -y install gcc
yum -y install gcc-c++
yum -y install make
2:拷贝 nginx 安装包到 nginx 服务器中并解压。进入nginx目录。
3: 编译nginx:
进入nginx目录。
3.1: ./configure
3.2: make
3.3: make install(nginx 安装在本机里,/usr/local/nginx)
4nginx的启动,停止,重新加载命令。
启动nginx
Cd /usr/local/nginx/sbin
./nginx
停止nginx
./nginx -s stop
重新加载配置文件:
./nginx -s reload
配置nginx的conf 目录下的nginx.conf文件。
upstream aa.com { #服务器集群名字
server 192.168.137.6:18080 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
server 192.168.137.7:28080 weight=1;
}
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://aa.com;
proxy_redirect default;
}
直接访问ngix服务器 weight为1时 将会访问 tomcat1 和 tomcat2 中的项目