Load balancing of Nginx under CentOS

Source: Internet
Author: User

192.168.55.115 Primary Server

192.168.55.185 is from server


You need to split the request sent to the server side, as follows


Require/index.php/* requests to access the primary server

/api.php/1/files/* request access to the primary server

/api.php/1/files_put/* request access to the primary server

/api.php/1/thumbnails/* request access to the primary server

/statics/thumbnails/* request access to the primary server


Everything else is accessed from the server



Server configuration for Primary server 192.168.55.115

Upstream Follower {server 192.168.55.185:80 max_fails=5 fail_timeout=360s;}
        server {Listen 80;
        server_name 192.168.55.115;
        Index index.html index.htm index.php;
        Root/www/web/sign_name;

        Client_max_body_size 10240m;
                Location ~ ^/index\.php\w*|/api\.php/\d+/(\bfiles\b|\bfiles_put\b|\bthumbnails\b)/\w* {set $script $uri;

                Set $path _info "";
                        if ($uri ~ "^ (. +.php) (/.+)") {set $script $;
                Set $path _info $;
                } Fastcgi_pass 127.0.0.1:9000;
                Fastcgi_index index.php;
                Fastcgi_param Script_filename/www/web/sign_name$fastcgi_script_name;
                Include Fastcgi_params;
                Fastcgi_param Script_name $script;
        Fastcgi_param path_info $path _info; } location ~ ^/statics/thumbnails/\w* {} location/{Proxy_pass http://follower;
                Proxy_set_header Host $http _host;
                Proxy_next_upstream error timeout Invalid_header http_500;

                Proxy_connect_timeout 360s; #rewrite ^ (. *?)
                api.php/(. *) $ $1api.php?$2; #rewrite ^ (. *?)
        index.php/(. *) $ $1index.php?$2; }
}


which

                Set $script $uri;
                Set $path _info "";

                if ($uri ~ "^ (. +.php) (/.+)") {
                        set $script $;
                        Set $path _info $
                }
The setup is to configure PHP's $_server[' path_info '] to get the full path problem, please refer to here



Server configuration from 192.168.55.185

server {
        listen       ;
        server_name  192.168.55.185;
        Index index.html index.htm index.php;
        Root/www/web/sign_name;
        Client_max_body_size 10240m;

        Location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                Fastcgi_index  index.php;
                Fastcgi_param  script_filename  /www/web/sign_name$fastcgi_script_name;
                Include        fastcgi_params;
        }

        Location/{
                rewrite ^ (. *?) api.php/(. *) $ $1api.php?$2;
                Rewrite ^ (. *?) index.php/(. *) $ $1index.php?$2;
        }
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.