以下是proxy_next_upstream和fastcgi_next_upstream的官方解释:

syntax: proxy_next_upstream[error|timeout|invalid_header|http_500|http_502|http_503|http_504|http_404|off];

default: proxy_next_upstreamerror timeout;

context: http,server, location

Directive determines in what cases the request will be transmitted to the nextserver:

error —an error has occurred while connecting to the server, sending a request to it,or reading its response;

timeout— occurred timeout during the connection with the server, transfer the requestor while reading response from the server;

invalid_header— server returned a empty or incorrect answer;

http_500— server returned answer with code 500

http_502— server returned answer with code 502

http_503— server returned answer with code 503

http_504— server returned answer with code 504

http_404— server returned answer with code 404

off — itforbids the request transfer to the next server

Transferringthe request to the next server is only possible when nothing has beentransferred to the client -- that is, if an error or timeout arises in themiddle of the transfer of the request, then it is not possible to retry thecurrent request on a different server.



===============================================================================================

fastcgi_next_upstream

syntax: fastcgi_next_upstreamerror|timeout|invalid_header|http_500|http_503|http_404|off

default: fastcgi_next_upstreamerror timeout

context: http,server, location

This directive defines in which cases request will be passed to the next server:

error —an error occurred during connection to the server, passing request to it orreading server respond header;

timeout— a timeout occurred during connection to the server, passing request to it orreading server respond header;

invalid_header— server returned empty or invalid answer;

http_500— server returned 500 respond;

http_503— server returned 503 respond;

http_404— server returned 404 respond;

off —explicitly forbids passing request to the next server;

Itshould be clear that passing request to the next server is possible only if nodata have been yet returned to the client. So, if the error or timeout occurredduring the data transmission to the client it's too late to fix it.

================================================

通过以上文字,我们可以看出其实fastcgi_next_upstream与proxy_next_upstream并没有本质上的区别,经过自己的验证,也证明了这个想法。并且,这两个参数是默认开启的。fastcgi_next_upstream error timeout;

proxy_next_upstream error timeout;

那么我们只需要找出fastcgi_next_upstream和error_page之间的区别就行了。

1 upstream backend_yyy{

2 server 192.168.133.92:9000 max_fails=3 fail_timeout=30s;

server 192.168.133.1:8003 max_fails=3 fail_timeout=30s;

# server 192.168.133.92:8000 max_fails=1 fail_timeout=3s weight=3;

}

upstream proxy_yyy{

server 42.62.24.82:80 ;

# server 192.168.133.100:80 ;

}


server {

listen 80 ;

server_name wangyanliang.dev.spriteapp.com;


access_log /data/logs/wangyanliang_access.log main;

error_log /data/logs/wangyanliang_error.log warn;


root /data/www/wangyanliang/;

index index.php;



error_page 403 404 = @fallback;

#error_page 502 403 404 = /2.txt;


location ~ \.php {

include fastcgi_params;

fastcgi_pass backend_yyy;

# error_page 502 403 404 = @fallback;

# fastcgi_next_upstream error http_503 http_500 timeout;

# fastcgi_next_upstream http_502 http_503 http_500 ;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}


location @fallback {

proxy_pass http://proxy_yyy;

}


经测试 error_page 设置在*.php{}里面是不会执行的。