nginx反向代理和负载均衡

来源:互联网 发布:色戒 梁朝伟 知乎 编辑:程序博客网 时间:2024/06/08 17:11

反向代理:

在nginx的location中使用proxy_pass http://xxxxx;即可实现反向代理到任意服务器

location ~* .php{    proxy_pass http://127.0.0.1:8080;}

负载均衡:

将多台服务器使用upstream绑定到一起取个名字,再使用proxy_pass代理到这个名字即可实现负载均衡

//此命令和location同级upstream httpserver{    server 127.0.0.1:81 weight=1 max_fails=2 fail_timeout=3;    server 127.0.0.1:82 weight=1 max_fails=2 fail_timeout=3;    //server的参数详解:    //  weight:权重    //  max_fails:最大连接失败的次数    //  fail_timeout:连接超时时间}//...location ~* .php{    proxy_pass http://httpserver;}