1.服务器要开启端口号
upstream fuzai.shenhongwei.top {
server 你的公网IP地址:8087 weight=5; #1
server 你的公网IP地址:8090 weight=10;#2
}
8087,8090端口需要开启 weight是权重,权重越高访问概率越高
2.
在负载均衡服务器上:
server
{
listen 8050;
server_name 你的域名;
location / {
proxy_pass 你的域名;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log /home/wwwlogs/access.log;
}
3.
分别在1服务器和2服务器
server
{
listen 8090; 或者8087
server_name 你的域名;
index index.php index.html;
root 文件路径;
#error_page 404 /404.html;
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
#include enable-php.conf;
location ~ .*\.(php|php7)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
4.重启nginx : service nginx restart
5.打开你的域名,测试即可