shell初学之nginx(负载均衡)

        创建三个以域名区分的网站a.com,b.com,c.com;访问a、b时,分别显示a、b两个网站的内容;访问c时,会出现依次显示两次a网站的内容,一次b网站的内容。

 1 #!/bin/bash
 2 setenforce 0
 3 sed -i 's/=enforcing/=disabled/g' /etc/sysconfig/selinux
 4 systemctl start firewalld
 5 systemctl enable firewalld
 6 yum -y install epel-*
 7 yum -y install nginx
 8 IP=`ifconfig |grep broad|grep -w inet |awk '{print $2}'`
 9 mkdir -p /work/html_a /work/html_b
10 echo "aaaaaaaaaaaaaa" > /work/html_a/index.html
11 echo "bbbbbbbbbbbbbb" > /work/html_b/index.html
12 echo "$IP a.com" >> /etc/hosts
13 echo "$IP b.com" >> /etc/hosts
14 echo "$IP c.com" >> /etc/hosts
15 echo "
16  server {
17        listen      80;
18        server_name a.com;
19        location / {
20        root /work/html_a;
21        }
22 }
23  server {
24        listen      80;
25        server_name b.com;
26        location / {
27        root /work/html_b;
28        }
29 }
30  server {
31        listen      80;
32        server_name c.com;
33        location / {
34        proxy_pass    http://abc;
35        }
36 }
37  upstream abc {
38     server    127.0.0.1:81 weight=2;
39     server    127.0.0.1:82 weight=1;
40 }
41  server {
42        listen      81;
43        server_name a.com;
44        location / {
45        root /work/html_a;
46        }
47 }
48  server {
49        listen      82;
50        server_name b.com;
51        location / {
52        root /work/html_b;
53        }
54 }
55 " > /etc/nginx/conf.d/abc.conf
56 nginx -t
57 systemctl restart nginx
58 systemctl enable nginx
59 firewall-cmd --add-port=80/tcp --permanent
60 firewall-cmd --reload

 

转载于:https://www.cnblogs.com/renyz/p/11294941.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值