Ngnix各项配置的意义( 二 )


ip_hash; #每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题,ip_hash不支持weight和backup
 
server 192.168.5.91:7878 max_fails=2 fail_timeout=10s;
server 192.168.5.92:7878 max_fails=2 fail_timeout=10s;
【Ngnix各项配置的意义】 
#server 192.168.5.91:7878 max_fails=2 fail_timeout=10s weight=1;
#server 192.168.5.92:7878 max_fails=2 fail_timeout=10s weight=2;
#server 192.168.5.90:7878 backup; #热备
}
 
#error_page 404 https://www.baidu.com; #错误页
 
server {
keepalive_requests 120; #单连接请求上限次数
listen 9080; #监听端口
server_name localhost; #监听地址 127.0.0.1
#charset koi8-r;
 
#access_log logs/host.access.log main;
#location ~*^.+$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写 。
# #root path; #根目录
# #index vv.txt; #设置默认页
# proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表
# deny 127.0.0.1; #拒绝的ip
# allow 172.18.5.54; #允许的ip
#}
location /test {
 
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_next_upstream_timeout 10s;
proxy_next_upstream_tries 2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header upstream_addr $upstream_addr;
 
proxy_pass http://mysvr;
 
}
 
#nginx主页
location / {
root html;
index index.html index.htm;
}
 
#用lua脚本向reids存值
location /lua/set {
default_type 'text/plain';
content_by_lua_file conf/lua/setKeyValue.lua;
}
 
#用lua脚本从reids取值
location /lua/get {
default_type 'text/plain';
content_by_lua_file conf/lua/getKey.lua;
}
 
#静态资源代理
location ~ .*.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /var/local/static;
expires 30d;
}
 
#error_page 404 /404.html;
 
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
 
}




推荐阅读