#最大连接数 一般设置为1万---10万
events {
worker_connections 1024;
}
#处理http请求
http{
#迷你类型 安全性高
include mime.types;
#查看访问量 一条以下的记录就是一个访问
#192.168.119.1 - - [26/Dec/2017:17:36:15 +0800] "GET /EsayUi/curd.html HTTP/1.1" 200 9757
#"http://192.168.119.128/EsayUi/layout.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
#(KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"
#access_log logs/access.log main;
#linux的独有的传送文件
sendfile on;
#长连接
keepalive_timeout 65;
#负载均衡 详情查看http://blog.csdn.net/panhaigang123/article/details/78903854
upstream backend {
server 192.168.119.1:8080 max_fails=3 fail_timeout=30s;
server 192.168.119.128:8080 max_fails=3 fail_timeout=30s;
#有状态的访问
session_sticky;
#健康检查模块
#interval:向后端发送的健康检查包的间隔(每隔三秒询问一次)。
#fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
#rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
#timeout: 后端健康请求的超时时间。
#type:健康检查包的类型,现在支持以下多种类型
#tcp:简单的tcp连接,如果连接成功,就说明后端正常。
#ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。
#http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
#mysql: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。
#ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
#通过下面的方式发送
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
#响应下面的http_2xx http_3xx; 表示正常
check_http_expect_alive http_2xx http_3xx;
}
#发送者
server {
#端口
listen 80;
#发送者名======本机
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
#发送负载均衡
location / {
root html;
index index.html index.htm;
proxy_pass http://backend;
#可以拦截访问的路径
}
#除了这个路劲不发送负载均衡 检查健康状态
location /status {
check_status;
#auth_basic 设置标题
auth_basic "请输入账号和密码";
#设置账号和密码 指向的文件 全路径 可以安装加密生成器 yum -y install httpd 执行 htpasswd -nb 账号 密码
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
access_log off;
#允许访问者 allow all(允许所有人访问)
allow 192.168.119.1;
#不允许其他访问
deny all;
}
#error_page 404 /404.html;
#redirect server error pages to the static page /50x.html
#返回的页面状态
error_page 500 502 503 504 /50x.html;
#自定义的错误 进入 cd /usr/local/nginx/html 创建一个html文件
error_page 505 /my505.html;
#响应的页面指定的路径
location = /50x.html {
root html;
}
#自定义错误要指定路径
location = /my505.html {
#注意要全路径
root /usr/local/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#location ~ /\.ht {
# deny all;
#}
}
......
}
events {
worker_connections 1024;
}
#处理http请求
http{
#迷你类型 安全性高
include mime.types;
#查看访问量 一条以下的记录就是一个访问
#192.168.119.1 - - [26/Dec/2017:17:36:15 +0800] "GET /EsayUi/curd.html HTTP/1.1" 200 9757
#"http://192.168.119.128/EsayUi/layout.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
#(KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"
#access_log logs/access.log main;
#linux的独有的传送文件
sendfile on;
#长连接
keepalive_timeout 65;
#负载均衡 详情查看http://blog.csdn.net/panhaigang123/article/details/78903854
upstream backend {
server 192.168.119.1:8080 max_fails=3 fail_timeout=30s;
server 192.168.119.128:8080 max_fails=3 fail_timeout=30s;
#有状态的访问
session_sticky;
#健康检查模块
#interval:向后端发送的健康检查包的间隔(每隔三秒询问一次)。
#fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
#rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
#timeout: 后端健康请求的超时时间。
#type:健康检查包的类型,现在支持以下多种类型
#tcp:简单的tcp连接,如果连接成功,就说明后端正常。
#ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。
#http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
#mysql: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。
#ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
#通过下面的方式发送
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
#响应下面的http_2xx http_3xx; 表示正常
check_http_expect_alive http_2xx http_3xx;
}
#发送者
server {
#端口
listen 80;
#发送者名======本机
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
#发送负载均衡
location / {
root html;
index index.html index.htm;
proxy_pass http://backend;
#可以拦截访问的路径
if ( $uri ~* ^/admin/.*$) {
#返回给请求者一个页面
return 505;
}}
#除了这个路劲不发送负载均衡 检查健康状态
location /status {
check_status;
#auth_basic 设置标题
auth_basic "请输入账号和密码";
#设置账号和密码 指向的文件 全路径 可以安装加密生成器 yum -y install httpd 执行 htpasswd -nb 账号 密码
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
access_log off;
#允许访问者 allow all(允许所有人访问)
allow 192.168.119.1;
#不允许其他访问
deny all;
}
#error_page 404 /404.html;
#redirect server error pages to the static page /50x.html
#返回的页面状态
error_page 500 502 503 504 /50x.html;
#自定义的错误 进入 cd /usr/local/nginx/html 创建一个html文件
error_page 505 /my505.html;
#响应的页面指定的路径
location = /50x.html {
root html;
}
#自定义错误要指定路径
location = /my505.html {
#注意要全路径
root /usr/local/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#location ~ /\.ht {
# deny all;
#}
}
......
}