多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## Nginx ### 反向代理 正向代理:代理的客户端,比如翻墙软件 反向代理:代理的服务器,对外隐藏了服务端的真实的ip和port ``` server{ listen 80; server_name xxx.com //ip location / { root html; //举例 proxy_pass http://ip:port; index index.html index.htm; //举例 } } ``` ### 负载均衡 ``` upstream myserver{ server 208.111.203.11:8801 server 208.111.203.11:8802 } server{ listen 80; server_name xxx.com //或者ip location / { root html; //举例 proxy_pass http://myserver;// 在这里 index index.html index.htm; //举例 } } ``` #### 负载均衡方式 >ip_hash ``` upstream myserver{ ip_hash; server 208.111.203.11:8801; server 208.111.203.11:8802; } ``` >weight 权重 ``` upstream myserver{ server 208.111.203.11:8801 weight=7; server 208.111.203.11:8802 weight=3; } ``` >fair ``` upstream myserver{ server 208.111.203.11:8801; server 208.111.203.11:8802; fair; } ``` ### 重定向 #### 访问a页面重定向到b页面 ``` server{ listen 80; server_name localhost; location / { root html; index index.html index.htm; rewrite /a.html /b.html; } ``` #### 访问当前nginx,重定向到其他网址 **eg** 访问www.a.com 跳转到 www.b.com ``` server{ listen 80; server_name www.a.com; rewrite ^/ http://www.b.com/; location / { root html; index index.html index.htm; } ```