欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

阿岳之_nginx负载均衡篇(二)

程序员文章站 2022-05-07 20:49:38
...
需要模块:ngx_http_upstream_module + ngx_http_proxy_module 或者 ngx_http_upstream_module + ngx_http_fastcgi_module

小知识:upstream 只能应用于http上下文,而proxy_pass可以应用于location,if in location, limit_except上下文

先尝试基于http协议的反向代理:

vim /etc/nginx/nginx.conf, 在http{}中添加如下配置:


server {
listen 80;
server_name www.a.com;
root /usr/share/nginx;
location / {
proxy_pass http://myapps/;
}
}
upstream myapps{
server 172.16.52.59 weight=1 max_fails=2 fail_timeout=4s;
server 172.16.52.60 weight=1 max_fails=2 fail_timeout=4s;
#ip_hash;
#health_check interval=3s fails_number=2;
}

测试:浏览器中输入www.a.com

以上就介绍了阿岳之_nginx负载均衡篇(二),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。