1,505   Nginx

Nginx 提供了ngx_http_upstream_module实现集群负载均衡,下面以PHP的fastcgi_pass为例

示例代码:

http{

        // 定义一个集群click_php_fpm 
	upstream click_php_fpm {
                // 集群服务器之一,weight是权重
		server 10.118.27.136:9000 weight=1;
		server 10.118.27.161:9000 weight=1;
		keepalive 8;
	}


	server {
		listen       80;
		server_name  localhost;

		location = /check {
                        // 使用集群click_php_fpm
			fastcgi_pass   click_php_fpm;
			fastcgi_param  SCRIPT_FILENAME  /mnt/hgfs/ShareFolder/web/click/check.php;
			include        fastcgi_params;
			fastcgi_keep_conn on;
		}

		location = /click {
                        // 使用集群click_php_fpm
			fastcgi_pass   click_php_fpm;
			fastcgi_param  SCRIPT_FILENAME  /mnt/hgfs/ShareFolder/web/click/click.php;      
			include        fastcgi_params;
			fastcgi_keep_conn on;
		}


	}

}


更多配置请查看官网




Leave a Reply

Your email address will not be published. Required fields are marked *