一.安装nignx
解压
tar -zxvf nginx-1.8.0.tar.gz
新加文件夹
mkdir /root/nginx
进入目录
cd nginx-1.8.0
设置一下配置信息,或者不执行此步,直接默认配置
./configure --prefix=/root/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_realip_module
编译
make
安装
make install
配置两个项目的tomcat集群:
cd nginx/conf/
vim nginx.conf
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local]"$request" '
# '$status $body_bytes_sent"$http_referer" '
# '"$http_user_agent""$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream q1 {
server127.0.0.1:8080 weight=5;
server127.0.0.1:8081 weight=5;
server127.0.0.1:8082 weight=5;
server127.0.0.1:8083 weight=5;
}
upstream q2 {
server123.45.22.222:8080 weight=5;
server123.45.22.222:8090 weight=5;
}
server {
listen 80;
server_name localhost;
#charsetkoi8-r;
#access_log logs/host.access.log main;
location/项目名1 {
root html;
index index.html index.htm;
proxy_pass http://q1;
}
location /项目名2 {
root html;
index index.html index.htm;
proxy_pass http://q2;
}
#error_page 404 /404.html;
80为监听的默认端口号,可以修改
二.启动nginx
三.修改server.xml端口号(4个)
cd /usr/local/tomcat04/conf
vim server.xml
注:每个配置文件修改3个端口号:8005 8009 8080
四.启动4个tomcat
-------------------------------------------------------------------------------------
启动停止重启与测试
1) 启动
#方法1 指定配置文件启动
# /usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf
#方法2 默认的配置文件
# cd /usr/local/nginx/sbin
# ./nginx
2) 停止
#查询nginx主进程号
ps -ef | grep nginx
#强制停止
pkill -9 nginx
3) 重启
/usr/local/nginx/sbin/nginx -s reload
4) 测试
#测试端口
netstat -na | grep 80
#浏览器中测试
http://ip:80