创建三个以域名区分的网站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