26 2021

主站负载均衡

访问主站host.index.com 轮询到 host.cluster.com集群

nginx监听80端口,当前拥有两台服务器

主服务器:192.168.1.5

备服务器:192.168.1.7

主服务器nginx.conf加入集群配置 include vhost/*.conf;

upstream host.cluster.com{

server 192.168.1.7:8081;    #php echo 1.7:8081 

server 192.168.1.7:8082;    #echo 1.7:8082   

server 192.168.1.5:8081;    #echo 1.5:8081 

server 192.168.1.5:8082;    #echo 1.5:8082 

主站监听

server { 

        listen       80;

        server_name  host.index.com; 

        #配置proxy

location / {

            proxy_pass   http://host.cluster.com;

        }

}


主服务器:192.168.1.5 nginx.conf 配置站点 host.n1.com:8082/host.n1.com:8081 

server {

        listen       8081;

        server_name  host.n1.com; 

        #charset koi8-r;


        #access_log  logs/host.access.log  main;

        root    "D:/R-MYWORK/18_php_work/host.n1.com";

        location / {

            index   index.php l.php;

           autoindex  off;

        }

        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php(.*)$  {

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            fastcgi_param  PATH_INFO  $fastcgi_path_info;

            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;

            include        fastcgi_params;

        }


        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #} 

}

备服务器:192.168.1.7 nginx.conf 配置站点 host.n1.com:8082/host.n1.com:8081 

打开浏览器访问:http://host.index.com 

轮询输出: 1.5:8081 、 1.5:8082  1.7:8081  1.7:8082 

注:以上内容仅供参考

笔记时间:2015-08-28

延伸阅读
  1. Mysql master slave Example
  2. linux禁用root登录