您的位置 首页 nginx

Nginx 负载均衡设置

Nginx 负载均衡设置

过程

 

WEB01配置简单的页面:
[root@web01 conf.d]# vim test.conf

[root@web01 /etc/nginx/conf.d]#vim test.conf
server {
listen 8081;
server_name test.baimei.com;

location / {
root /code/test;
index index.html;
}
}

 

mkdir /code/test
echo web01....... > /code/test/index.html
nginx -t
nginx -s reload
lsof -i:8080

 

WEB02服务器配置简单的页面:

[root@web02 /etc/nginx/conf.d]#vim test.conf

server {
listen 8082;
server_name test.baimei.com;

location / {
root /code/test;
index index.html;
}
}

 

mkdir /code/test
echo web02.... > /code/test/index.html
nginx -t
nginx -s reload

 

安装 模块 upstream_check 负载均衡健康检查 步骤:

安装 完 upstream_check 后  使用健康状态检查模块:

代理服务器配置:   (nginx 负载均衡服务器,单独的一台服务器)

也可以跟其他的一起用

cat upstream.conf

upstream webs1 {
server 172.16.1.7:8080;
server 172.16.1.8:8082;
}

server {
listen 80;
server_name test.baimei.com;

location / {
proxy_pass http://webs1;

#请求时携带的参数配置
include proxy_params;
}
location /upstream_check {
check_status;
}
}

 

 

注意这个地方要有 配置文件:

include proxy_params;   

vim /etc/nginx/proxy_params

 

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;

proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;

 

nginx -t

 

负载均衡 可以查看: http://test.baimei.com/

访问: test.baimei.com/upstream_check   

(要配置hosts)

如下图所示:

安装phpmyadmin

linux 安装phpadmin(phpmyadmin)

扩展测试: wordpress 负载均衡设置:

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章