[root@ conf.d]# cat load_blance.conf
upstream load_blance_fcgi{
ip_hash;
server 192.168.1.139:9000;
server 192.168.1.140:9000;
}
upstream multi_point_fcgi{
server 192.168.1.139:9000;
server 192.168.1.140:9000;
}
upstream single_point_fcgi{
server 192.168.1.140:9000;
}
server
{
listen 80;
server_name www1.test.com;
index index.html index.htm index.php;
root /webroot/load_blance;
location ~ \.php$ {
fastcgi_pass load_blance_fcgi;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server
{
listen 80;
server_name www2.test.com;
index index.html index.htm index.php;
root /webroot/load_blance;
location ~ \.php$ {
fastcgi_pass multi_point_fcgi;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server
{
listen 80;
server_name www3.test.com;
index index.html index.htm index.php;
root /webroot/load_blance;
location ~ \.php$ {
fastcgi_pass single_point_fcgi;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
upstream load_blance_fcgi{
ip_hash;
server 192.168.1.139:9000;
server 192.168.1.140:9000;
}
upstream multi_point_fcgi{
server 192.168.1.139:9000;
server 192.168.1.140:9000;
}
upstream single_point_fcgi{
server 192.168.1.140:9000;
}
server
{
listen 80;
server_name www1.test.com;
index index.html index.htm index.php;
root /webroot/load_blance;
location ~ \.php$ {
fastcgi_pass load_blance_fcgi;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server
{
listen 80;
server_name www2.test.com;
index index.html index.htm index.php;
root /webroot/load_blance;
location ~ \.php$ {
fastcgi_pass multi_point_fcgi;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server
{
listen 80;
server_name www3.test.com;
index index.html index.htm index.php;
root /webroot/load_blance;
location ~ \.php$ {
fastcgi_pass single_point_fcgi;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
测试:
访问http://www1.test.com/ nginx会根据源IP地址将请求抛给后端139或140上的Fastcgi处理
访问http://www2.test.com/ nginx会轮训将请求抛给后端139,140上的Fastcgi处理
访问http://www3.test.com/ nginx会将请求只抛给140上的Fastcgi处理
转载于:https://blog.51cto.com/aimin/1135518