1、打开nginx的官网:http://nginx.org/,下载最新的稳定版本并安装。
2、安装两个tomcat放到nginx同目录下,修改端口号(service.xml)。
3、把项目放到两个tomcat下并启动tomcat
1.1启动命令 windows linux
查看文件夹子目录 dir ls
打开文件夹 ——— cd ———
启动命令 start *.bat ./*.sh
停止命令 stop *.bat ./*.sh
4、配置nginx
修改nginx.conf文件
upstream localhost {//服务器列表
server localhost:8080 weight=1;//weight 给nginx代理服务器分配权重 weigth值越大,访问次数越多
server localhost:8081 weight=1;
}
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm index.jsp;
proxy_set_header Host $host:$server_port;
proxy_redirect http://localhost http://localhost:8888;
proxy_pass http://localhost;//代理服务器
}
location ~ \.jsp$ {
proxy_pass http://localhost;
}
服务器列表
server localhost:8080 weight=1;//weight 给nginx代理服务器分配权重 weigth值越大,访问次数越多
server localhost:8081 weight=1;
}
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm index.jsp;
proxy_set_header Host $host:$server_port;
proxy_redirect http://localhost http://localhost:8888;
proxy_pass http://localhost;//代理服务器
}
location ~ \.jsp$ {
proxy_pass http://localhost;
}
启动nginx
启动服务:start nginx
停止服务:nginx -s stop
重新加载:nginx -s reload(配置文件被修改后需要执行它)