nginx配置文件,最好每个域名一个
${nginx}/conf/nginx.conf
文件末尾加include vhost/*.conf;
nginx启动
Mac/Linux : /usr/|oca|/nginx/sbin/nginx.sh
Windows : ${nginx}/nginx.exe 也最好在命令行启动,因为双击启动正常也是闪退
默认端口是80
重启
linux:
${nginx}/sbin/ sudo ./nginx -s reload
windows:
1.轮询:
默认的,但是不能考虑到每台机器的差异,比如有的机器还要定时任务,负担更重
upstream www.happymmall.com{
server www.happymmall.com:8080;
server www.happymmall.com:9080;
}
2.权重,用得最多的
upstream www.happymma|l.com{
server www.happymmall.comz8080 weight=15;
server www.happymmall.comz9080 weight=10;
}
3.ip hash
保证同一个ip下次还是到同个tomcat,但是可能不均衡,ip也可能变
upstream www.happymma|l.com{
ip_hash;
server www.happymmall.com:8080;
server www.happymmal l.comz9080;
}
4.url hash(第三方插件
实现一个服务访问同个tomcat,缺点还是不平均,有的url请求会频繁
upstream www.happymmall.com{
server www.happymmall.comz8080;
server www.happymmall.com:9080;
hash $request_uri;
}
5.fair(第三方插件
响应时间短的优先分配
upstream www.happymmall.com{
server www.happymmall.comz8080;
server www.happymmall.com:9080;
fair;
}
再看看统一看下
upstream backserver{
# 保证同一个ip下次还是到同个tomcat
ip_hash;
# 暂时不用
server 127.0.0.1:9090 down;
#权重2
server 127.0.0.1:8080 weight=2;
#权重1
server 127.0.0.1:6060;
#备用:撑不住时用这个
server 127.0.0.1:7070 backup;
}