珀耳塞福建 发表于 2018-11-15 06:50:24

Nginx 负载均衡实验(一)

  服务器 A :192.168.65.102   服务器 B :192.168.65.103   服务器 C :192.168.65.104
  


  

  一、确认 102、103、104 已存在Nginx,102已开启Nginx
  


  

  二、修改 102 nginx.conf 配置文件
  

  

注意:proxy_pass 参数需要对应 upstream 的名称三、修改 103 和 104 服务器的 nginc.conf  

  


  


[*]#102 加入
[*]upstream luwen02.com2{
[*]      server 192.168.65.103;
[*]      server 192.168.65.104;
[*]}
[*]server {
[*]      listen 192.168.65.102:80;
[*]      server_name 192.168.65.102;
[*]
[*]      location / {
[*]                proxy_set_header      Host $host;
[*]                proxy_set_header      X-Real-IP $remote_addr;
[*]                proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
[*]                client_max_body_size    32m;
[*]                client_body_buffer_size 256k;
[*]                proxy_pass http://luwen02.com2;
[*]      }
[*]      access_log/var/log/nginx/nginx-access.log;
[*]}
[*]
  

  

#103 / 104修改   
[*]server
[*]{
[*]    listen       80 default;
[*]    server_name192.168.65.102;
[*]    index index.html index.htm index.php;
[*]    root/data/httpd/;
[*]    location ~ .*\.php.*
[*]    {
[*]      include php_fcgi.conf;
[*]      include pathinfo.conf;
[*]    }
[*]    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
[*]    {
[*]      expires      30d;
[*]    }
[*]    location ~ .*\.(js|css)?$
[*]    {
[*]      expires      1h;
[*]    }
[*]    access_log /var/log/nginx/access.log;
[*]    #access_log off;
[*]}
  

注意:server_name 必须指向负载均衡分配的服务器地址上。也就是102这台服务器。  
四、分别检查 102、103、104 配置文件 /usr/local/nginx/sbin/nginx -t
  

  

五、分别重启 102、103、104 nginx 服务器 /etc/init.d/nginx restart  

六、访问 192.168.65.102 的 index.html  

  

  

  

  

  



页: [1]
查看完整版本: Nginx 负载均衡实验(一)