upstream: ip_hash and backup

husseingalal nginx-forum at nginx.us
Mon Aug 11 10:15:50 UTC 2014


Hello,
i have this little solution of load balancer at the front end using nginx
and two php-fpm application servers at the backend and i installed php-fpm
on the load balancer as a backup application server, i wanted to use ip_hash
with backup i tried your solution but it keep giving me 502 bad gateway
errors.
this is my configuration
upstream apps {
        ip_hash;
        server 10.128.149.234:9000;
        server 10.128.151.32:9000;
}
upstream backup {
        server unix:/var/run/php5-fpm.sock;
}



server {

        listen 80 default_server;
        index index.php;
        root /var/www/wp;
        server_name .example.com;
        set $mreq 1;
        if ( $request_method = POST ){
                set $mreq 0;
        }
        if ( $uri ~ "/wp-" ) {
set $mreq 0;
        }
        if ($http_cookie ~*
"comment_author_|wordpressuser_|wp-postpass_|wordpre
ss_logged_in_" ) {
                set $mreq 0;
                                }

        location / {

                default_type text/html;
                fastcgi_index index.php;
                include fastcgi_params;
                index index.php;
                if ( $mreq = 1){
                        add_header uri $request_uri;
                        set $memcached_key
data-$scheme://$host$request_uri;
                        memcached_pass 104.131.208.224:11211;
                        error_page 404 500 502 = @fallback;
                }

                if ( $uri ~ \.php$ ) {
                fastcgi_pass apps;
                error_page 502 504 = @fallbackbackup;
                                          }
        }
        location @fallback {

                if ( $uri ~ \.php$ ) {
                fastcgi_pass apps;
                error_page 502 504 = @fallbackbackup;

        }
        }
        location @fallbackbackup {
                fastcgi_pass backup;
}
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,211408,252480#msg-252480



More information about the nginx mailing list