(在两台前端服务器上配置)
[root@centos-1 ~]# vim/usr/local/nginx/conf/nginx.conf
……
……
……
upstreambackend {
ip_hash;
server 192.168.5.131:80 max_fails=2fail_timeout=30s;
server 192.168.5.132:80 max_fails=2fail_timeout=30s;
#ip_hash: 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
#max_fails=2 为允许失败的次数,默认值为1
#fail_timeout=30s 当max_fails次失败后,暂停将请求分发到该后端服务器的时间
}
proxy_temp_path /usr/local/nginx/cache/tmp 1 2;
proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=cache1:100m inactive=1dmax_size=10g;
……
……
……
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache cache1;
add_header X-Cache$upstream_cache_status;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 10m;
expires 30d;
# root /web;
index index.php index.html index.htm;
}
[root@centos-2 ~]# vim/usr/local/nginx/conf/nginx.conf
……
……
……
upstreambackend {
ip_hash;
server 192.168.5.131:80 max_fails=2fail_timeout=30s;
server 192.168.5.132:80 max_fails=2fail_timeout=30s;
}
proxy_temp_path /usr/local/nginx/cache/tmp 1 2;
proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=cache1:100m inactive=1dmax_size=10g;
……
……
……
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache cache1;
add_header X-Cache$upstream_cache_status;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 10m;
expires 30d;
# root /web;
index index.php index.html index.htm;
}