貌似好久没有更新文章了…实在是忙呐 今天就nginx负载转发配置写个简单流程配置,以做记录
俩台服务器为例子
其实https转发也基本和80类似 你每个nginx都需要加ssl证书 转发机nginx监听443端口即可 其他机子没有必要
A服务器 192.168.1.1 做为主转发服务器 同时转发给自己
B服务器 192.168.1.2
A服务器配置如下
#nginx服务器负载模块 upstream www{ server 192.168.1.1:8081 weight=10 fail_timeout=60s max_fails=10; server 192.168.1.2:8082 weight=10 fail_timeout=60s max_fails=10; } server { listen 80; #监听80 也可以443 server_name xxx.com #主域名 root /data/wwwroot/; index index.html index.htm index.php; #如果监听443需要加证书路径 配置等 location / { proxy_pass http://www/; #这里注意的是 如果你是https 443端口 一定要写成proxy_pass https://www/; proxy_connect_timeout 2s; proxy_set_header Host $host; } } #处理转发给自己的请求 server { listen 8081; server_name 192.168.1.1 root /data/wwwroot/; index index.html index.htm index.php; #如果监听443需要加证书路径 配置等 location / { #这里配置省略 } }
B服务器配置如下
#处理A服务器转发给自己的请求 server { listen 8082; server_name 192.168.1.2 root /data/wwwroot/; index index.html index.htm index.php; #如果监听443需要加证书路径 配置等 location / { #这里配置省略 } }
这里其实简单的负载就做好了,大家可以在网站目录俩台服务器放不同的内容输出,就可以看到效果啦