java nginx 502_Nginx 负载均衡如何配置,高并发报502如何返回正常信息?

负载均衡入口服务器配置

入口

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;

#遇到502、503、504等状态码时,我们可以改变将之成200,这样在调用接口时,就可以正常的返回信息,给用户提供良好的交互环境。

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

location /dealwith_502{

#下面这些header,是为了防止跨域问题

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": "系统繁忙,请稍后访问", "data": [] }';

if ( $arg_callback != "" )

{

return 200 'try{$arg_callback($ret_body)}catch(e){}';

}

return 200 $ret_body;

}

location / {

root html;

proxy_set_header Host $host;

index index.php index.html index.htm;

}

}

服务器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": "系统繁忙,请稍后访问", "data": [] }';

if ( $arg_callback != "" )

{

return 200 'try{$arg_callback($ret_body)}catch(e){}';

}

return 200 $ret_body;

}

location / {

if (!-e $request_filename) {

rewrite ^(.*)$ /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;

}

}

其他服务器配置和服务器1的配置是相同的,这样就可以避免高并发的出现。我做的项目就是这样处理的。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值