nginx做负载的时候需注意:
nginx有重试机制,可以通过proxy_next_upstream,指定请求传递到下一个服务器。默认404状态码是不会被传递的。需要指定:proxy_next_upstream error timeout http_404;(默认不转发post)
proxy_next_upstream error timeout http_404 non_idempotent;(转发post)
例如:
upstream oa_server {
# ip hash
server 127.0.0.1:9503 weight=2;
server 127.0.0.1:9501 weight=2;
}
server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/tp5/public/static;
index index.html index.htm index.php;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ /\. {
deny all;
}
location / {
if (!-e $request_filename){ #这里的if后需要加空格
proxy_pass http://oa_server;
proxy_next_upstream error timeout http_404 non_idempotent; #这里
}
}