NginX之一:window下安装部署与配置负载均衡

第一步:下载安装nginx,地址:http://nginx.org/en/docs/windows.html

下载完成,比如放在C盘根目录下:

cd c:\ unzip nginx-1.15.3.zip //解压文件 cd nginx-1.15.3 //进入目录 start nginx //启动服务

此时窗口一闪而过,如何检测服务是否启动了呢?(中文路径可能有问题)

运行tasklist检测服务是否正常启动:

如上图解释一个线程是master线程,一个是工作线程,如果服务没有启动成功,则logs文件夹下又错误日志。

第二步:配置2个tomcat,参考https://mp.csdn.net/postedit/75330982,配置2个tomcat复制集

设置tomcat1端口:8080

设置tomcat1端口:8081

第三部:配置nginx  负载均衡

修改nginx.conf文件:

1.在http节点下,添加upstream节点。

upstream tomcat{

server 127.0.0.1:8080;

server 127.0.0.1:8081;

}

2. 将server节点下的location节点中的proxy_pass配置为:http:// + upstream名称,即“

http://tomcat”.

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.html index.htm;

proxy_pass http://tomcat;

proxy_connect_timeout 1;

proxy_read_timeout 1;

proxy_send_timeout 1;

}

proxy_connect_timeout   这个参数, 这个参数是连接的超时时间。 我设置成1,表示是1秒后超时会连接到另外一台服务器。

 

第四步:重启nginx

执行命令:nginx -s stop 停止服务

start nginx //启动服务

浏览器地址栏输入:http://localhost 可以看到tomcat首页地址了

测试:tomcat两个首页做一下标识,然后停止一个tomcat会发现,nginx会跳转到活动的tomcat上,停止的不再提供服务,两个tomcat都启动会根据权重分配跳转到不同tomcat上。

 

常用nginx命令:

nginx -s stop

fast shutdown

nginx -s quit

graceful shutdown

nginx -s reload

changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes

nginx -s reopen

re-opening log files

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值