反向代理:
在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;}
以上就上有关nginx反向代理和负载均衡的全部内容,学步园全面介绍编程技术、操作系统、数据库、web前端技术等内容。