Load balancing entry server configuration

The entrance

upstream mServer{

Server 149.129.114.100:8080 weight=2 fail_timeout=30s max_fails=0;

Server 149.129.75.101:8080 weight=4 fail_timeout=30s max_fails=0;

Server 149.129.76.102:8080 weight=4 fail_timeout=30s max_fails=0;

}

server {

listen 80;

server_name www.xxx.com;

#charset koi8-r;

#access_log logs/host.access.log main;

# When the status code 502, 503, 504 is encountered, we can change it to 200, so that when the interface is called, the normal information can be returned, providing users with a good interaction environment.

error_page 502 503 504 =200 /dealwith_502? callback=$arg_callback;

location /dealwith_502{

The following headers are intended to prevent cross-domain problems

add_header ‘Content-Type’ ‘application/json; charset=utf-8’;

add_header ‘Access-Control-Allow-Origin’ ‘*’;

add_header ‘Access-Control-Allow-Headers’ ‘Origin, X-Requested-With, Content-Type, Accept’;

add_header ‘Access-Control-Allow-Methods’ ‘GET, POST, PUT’;

Set $ret_body ‘{” status “: 0,” info “, “system is busy, please wait a moment”, “data” : []}’;

if ( $arg_callback != “” )

{

return 200 ‘try{
a r g c a l l b a c k ( arg_callback(
ret_body)}catch(e){}’;

}

return 200 $ret_body;

}

location / {

root html;

proxy_pass http://mServer;

proxy_set_header Host $host;

index index.php index.html index.htm;

}

}

Server 1

server

{

listen 8080;

#listen [::]:80;

Server_name 149.129.114.100;

index home.html index.htm index.php default.html default.htm default.php;

root /home/wwwroot/xxx;

#error_page 404 /404.html;

error_page 502 503 504 =200 /dealwith_502? callback=$arg_callback;

location /dealwith_502{

add_header ‘Content-Type’ ‘application/json; charset=utf-8’;

add_header ‘Access-Control-Allow-Origin’ ‘*’;

add_header ‘Access-Control-Allow-Headers’ ‘Origin, X-Requested-With, Content-Type, Accept’;

add_header ‘Access-Control-Allow-Methods’ ‘GET, POST, PUT’;

Set $ret_body ‘{” status “: 0,” info “, “system is busy, please wait a moment”, “data” : []}’;

if ( $arg_callback != “” )

{

return 200 ‘try{
a r g c a l l b a c k ( arg_callback(
ret_body)}catch(e){}’;

}

return 200 $ret_body;

}

location / {

if (! -e $request_filename) {

rewrite ^(.*)
/ i n d e x . p h p / /index.php/
1 last;

break;

}

}

location ~ [^/].php(/|$)

{

comment try_files $uri =404; to enable pathinfo

#try_files $uri =404;

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

include pathinfo.conf;

fastcgi_param PHP_ADMIN_VALUE “open_basedir=/home/wwwroot/:/tmp/:/proc/”;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*.(js|css)? $

{

expires 12h;

}

}

The other server configurations are the same as those of server 1 to avoid high concurrency. That’s how I deal with my projects.