一.nginx Windows版本号:nginx-1.12.2
二.下载地址
https://download.csdn.net/download/cyw8998/26358326
或者http://nginx.org/download/nginx-1.12.2.zip
三.nginx基础命令:
解压后,启动nginx.exe 或者命令行启动 ./nginx
重启命令 nginx -s reload
快速关闭 nginx -s stop
有序关闭 nginx -s quit
四.负载均衡测试:
1.搭建两个web服务,同一机器端口号不同就行
2.修改nginx/conf/nginx.conf文件(nginx1.25版本中,是修改conf.d/default.conf )
upstream AAA{
server 172.16.10.226:19089 weight=7;
server 172.16.10.226:29089 weight=3;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://AAA;
proxy_redirect default;
root html;
index index.html index.htm;
}
......
}
upstream AAA{
server localhost:18001 weight=7; #服务1
server localhost:18002 weight=3; #服务2
##1.9.9以下版本可以进行心跳检查,1.10以上商业版本才能检查心跳
#check interval=7000 rise=3 fall=3 timeout=5000 type=http;
#check_http_send "GET / HTTP/1.0\r\n\r\n";
#check_http_expect_alive http_2xx http_3xx;
}
server {
listen 18000;
server_name localhost;
location / {
proxy_pass http://AAA;
proxy_redirect default;
root html;
index index.html index.htm;
}
........
}
之后访问http://localhost:18000 就可以看到随机跳转到18001或者18002