码迷,mamicode.com
首页 > 其他好文 > 详细

nginx反向代理负载均衡配置

时间:2017-04-04 01:26:57      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:nginx   负载均衡   

LB:

nginx.conf


worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream www_server_pools {
    server 192.1.1.9:80 weight=1;
    server 192.1.1.10:80 weight=1;
    }
    upstream bbs_server_pools {
    server 192.1.1.9:80 weight=1;
    server 192.1.1.10:80 weight=1;
    }
    server {
        listen          80;
        server_name     www.lufeng.com;
        location / {
        proxy_pass http://www_server_pools;
        include proxy.conf;
        }
    }
        server {
        listen          80;
        server_name     bbs.lufeng.com;
        location / {
        proxy_pass http://bbs_server_pools;
        include proxy.conf;
        }
    }
}

proxy.conf

        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;


WEB01  WEB02

worker_processes  1;
error_log  logs/error.log;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main     ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                         ‘$status $body_bytes_sent "$http_referer" ‘ 
                         ‘"$http_user_agent" "$http_x_forwarded_for"‘;
include extra/bbs.conf;
include extra/blog.conf;
include extra/www.conf;
}


bbs.conf

server {
       listen         80;
       server_name    bbs.lufeng.com;
       root      html/bbs;
       index     index.php index.html index.html; 
       location ~ .*\.(php|php5)?$ { 
                root    html/bbs; 
                fastcgi_pass    127.0.0.1:9000; 
                fastcgi_index   index.php; 
                include         fastcgi.conf; 
        }
        access_log   logs/access_bbs.log    main;
}

blog.conf

    server {
       listen         80;
       server_name    blog.lufeng.com;
       root      html/blog;
       index     index.php index.html index.html;
        location / {
        if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.html){
                rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
                rewrite (.*) /index.php;
        }
        }
        location ~ .*\.(php|php5)?$ {
                root    html/blog;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                include         fastcgi.conf;
        }
        access_log   logs/access_blog.log    main;
}


本文出自 “大梦初醒” 博客,请务必保留此出处http://bestlufeng.blog.51cto.com/11790256/1912677

nginx反向代理负载均衡配置

标签:nginx   负载均衡   

原文地址:http://bestlufeng.blog.51cto.com/11790256/1912677

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!