Nginx介绍
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务(电子邮箱协议)。
Nginx下载地址
网址: http://nginx.org/
下载地址: http://nginx.org/en/download.html
Nginx命令
1.nginx -s stop 关闭
2.start nginx 开启
3.nginx -s reload 重启
批量关闭nginx服务项:
taskkill /f /fi "imagename eq nginx.exe"
默认跳转localhost
http{
#反向代理 服务地址
server {
#默认端口
listen 80;
#服务名称
server_name localhost;
#配置具体路径 /拦截全部请求 / 利用正则实现路径的拦截
#就是请求的转发
location / {
#转向文件夹目录
root html;
#配置代理路径
#proxy_pass http://localhost:8091;
#系统默认跳转页面
index index.html index.htm;
}
}
}
负载均衡
tomcat集群
#定义tomcat集群 1.轮循策略 2.权重策略 3.iphash策略
upstream jtWindows {
#ip_hash;
server localhost:8081 weight=6 max_fails=1 fail_timeout=60s down;
server localhost:8082 weight=3 max_fails=1 fail_timeout=60s;
server localhost:8083 weight=1 max_fails=1 fail_timeout=60s backup;
}
1.down属性
说明:如果在服务器中标识down属性之后,该服务器将不会再为用户提供服务.
#定义tomcat集群 1.轮循策略 2.权重策略 3.iphash策略
upstream jtWindows {
#ip_hash;
server localhost:8081 weight=6 down;
server localhost:8082 weight=3;
server localhost:8083 weight=1;
}
2.backup属性
说明:如果需要在集群中设置备用机.则需要设置backup属性.
设置为备用机之后,当主机遇忙/主机宕机时生效.
#定义tomcat集群 1.轮循策略 2.权重策略 3.iphash策略
upstream jtWindows {
#ip_hash;
server localhost:8081 weight=6 down;
server localhost:8082 weight=3 down;
server localhost:8083 weight=1 backup;
}
3.Nginx实现tomcat高可用配置
属性说明:
max_fails=1 定义最大失败次数
fail_timeout=60s 设定失败的时间周期.
原理说明:当nginx访问后台服务器时,如果发现后台服务器连接不通.当失败次数达到了设定的最大次数时,则开启高可用的策略.规定用户在时间周期之内,不会再次访问故障机.
#搭建后台服务器.
server {
listen 80;
server_name manage.jt.com;
location / {
#配置代理路径
#proxy_pass http://localhost:8091;
proxy_pass http://jtWindows;
proxy_connect_timeout 2;
proxy_read_timeout 2;
proxy_send_timeout 2;
}
}
#定义tomcat集群 1.轮循策略 2.权重策略 3.iphash策略
upstream jtWindows {
#ip_hash;
server localhost:8081 weight=6 max_fails=1 fail_timeout=60s down;
server localhost:8082 weight=3 max_fails=1 fail_timeout=60s;
server localhost:8083 weight=1 max_fails=1 fail_timeout=60s backup;
}