posts - 68, comments - 19, trackbacks - 0, articles - 1

nginx负载均衡配置

Posted on 2018-09-15 23:08 viery 阅读(127) 评论(0)  编辑  收藏 所属分类: linux
1.准备3台服务器,可以在虚拟机上测试,都要安装nginx 
c01 nginx负载均衡服务器 192.168.38.128
c02 c03 web服务器 192.168.38.129/130

2.c02 c03 nginx.conf配置
 1 worker_processes  1;
 2 error_log logs/error.log;
 3 events {
 4     worker_connections  1024;
 5 }
 6 http {
 7     include       mime.types;
 8     default_type  application/octet-stream;
 9     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
10                       '$status $body_bytes_sent "$http_referer" '
11                       '"$http_user_agent" "$http_x_forwarded_for"';
12 
13     sendfile        on;
14     server_tokens off;
15     keepalive_timeout  65;
16     
17     server {
18         listen       80;
19         server_name  www.hello.org;
20 
21         location / {
22             root   html/www;
23             index  index.html index.htm;
24         }
25         access_log logs/access_www.log main;
26     }
27 }

3 /ect/hosts 配置ip和域名对应

4 curl测试web服务器解析结果是否正确

5.配置负载均衡服务器
 1 worker_processes  1;
 2 error_log logs/error.log;
 3 events {
 4     worker_connections  1024;
 5 }
 6 http {
 7     include       mime.types;
 8     default_type  application/octet-stream;
 9 
10     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
11                       '$status $body_bytes_sent "$http_referer" '
12                       '"$http_user_agent" "$http_x_forwarded_for"';
13 
14     sendfile        on;
15     server_tokens off;
16     keepalive_timeout  65;
17     upstream www_server_pools{
18         server 192.168.38.130:80 weight=1;
19         server 192.168.38.129:80 weight=1;
20     }
21     server{
22         listen 80;
23         server_name www.hello.org;
24         location / {
25                 proxy_pass http://www_server_pools;
26         }
27     }
28 }

6.在windows客户端配置etc目录下域名解析 
192.168.38.128 www.hello.org

在浏览器中输入www.hello.org,会按照配置文件中的weight比例交替出现c02和c03web服务器。

只有注册用户登录后才能发表评论。


网站导航: