http2

練習:

    (1)基于主機名實現三個虛擬主機

    (2) 每虛擬主機使用獨立的訪問日志和錯誤日志

    (3) 第三個虛擬主機的/admin要進行用戶訪問認證

    (4) 在第二個虛擬主機上提供/status;

    (5) 在第三個虛擬主機提供路徑別名/bbs,訪問其它文件系統路徑;

    (6) 嘗試使用混合類型的虛擬主機:

    基于IP,PORT和ServerName

<VirtualHost 10.1.0.249:80>
    ServerName www.a.com
    DocumentRoot "/www/a/html/"
    <Directory "/www/a/html/">
        Options none
        AllowOverride none
        require all granted
    </Directory>
    ErrorLog "/www/a/html/error_log"
    LogLevel warn
    CustomLog "/www/a/html/access_log" combined
</VirtualHost>

Listen 8080
<VirtualHost 10.1.0.249:8080>
    ServerName www.b.com
    DocumentRoot "/www/b/html/"
    <Directory "/www/b/html/">
        Options none
        AllowOverride none
        require all granted
    </Directory>
    <Location /status>
        Sethandler server-status
        Require all granted
    </Location>
    ErrorLog "/www/b/html/error_log"
    LogLevel warn
    CustomLog "/www/b/html/access_log" combined
</VirtualHost>

<VirtualHost 10.1.0.248:80>
    ServerName www.c.com
    DocumentRoot "/www/c/html/"
    <Directory "/www/c/html/">
        Options none
        AllowOverride none
        require all granted
    </Directory>
    <Directory "/www/c/html/admin">
        Options indexes
        AllowOverride none
        AuthType basic
        AuthName "admin and passwd"
        AuthUserFile "/etc/httpd/conf.d/.htpasswd"
        require valid-user
    </Directory>
    Alias /bbs/ "/"
    <Directory "/">
        Options Indexes FollowSymLinks
        AllowOverride none
        require all granted
    </Directory>
    ErrorLog "/www/c/html/error_log"
    LogLevel warn
    CustomLog "/www/c/html/access_log" combined
</VirtualHost>

練習2:

    使用腳本實現以上功能

     每虛擬使用單獨的配置文件

     腳本可接受參數,參數虛擬主機名稱

[root@CentOS7 ~]# cat httpd.sh 
#!/bin/bash
#description : create virtualhost 
#version 0.1
#author gm
#date 20161007
#

create_vir (){
cat > /etc/httpd/conf.d/${domain_name}.conf << END
<VirtualHost *:80>
    Servername ${domain_name}
    DocumentRoot "${vir_path}"
    <Directory "${vir_path}">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
    ErrorLog "${vir_path}/error.log"
    LogLevel warn
    CustomLog "${vir_path}/access.log" combined
</VirtualHost>
END
}

create_status () {
sed -i '/<\/Directory>/a \\t<Location "/status">\n\t\tSetHandler server-status\n\t\t\ <末尾的\表示換行,請刪除>
Require all granted\n\t</Location>' /etc/httpd/conf.d/${domain_name}.conf
}

create_authdir () {
#read -p "Input dir of Authrization: " dir
mkdir ${vir_path}/admin
touch /etc/httpd/conf.d/.${domain_name}
read -p "Input One UserName: " username
while [ $username != exit ]; do
    htpasswd -b -m /etc/httpd/conf.d/.${domain_name} $username 123456
    read -p "Input One UserName Or Input exit: " username
done
echo "admin test" > ${vir_path}/admin/index.html
sed -i '/<\/Directory>/a \\t<Location "/admin">\n\t\tOptions none\n\t\tAllowOverride none\  <末尾的\表示換行,請刪除>
\n\t\tAuthType basic\n\t\tAuthName "admin and passwd"\n\t\tAuthUserFile /etc/httpd/conf.d\  <末尾的\表示換行,請刪除>
/.www.gm.com\n\t\tRequire valid-user\n\t</Location>' /etc/httpd/conf.d/${domain_name}.conf
}

create_aliasdir () {
#read -p "Input dir of Alias: " dir1
#read -p "Input dir of xxxxx: " dir2
mkdir ${vir_path}/bbs
sed -i '/<\/Directory>/a \\tAlias /bbs/ "/"\n\t<Directory "/">\n\t\tOptions indexes\n\t\t\
AllowOverride none\n\t\tRequire all granted\n\t</Directory>' /etc/httpd/conf.d/${domain_name}.conf
}

#create configure file
read -p "Input one domain name: " domain_name
if [ -e /etc/httpd/conf.d/${domain_name}.conf ] ; then
    echo "This virtualhost is created."
    exit 1
else
    touch /etc/httpd/conf.d/${domain_name}.conf
fi

#change DocumentRoot
sed -i 's@^DocumentRoot\>.*@#&@' /etc/httpd/conf/httpd.conf && echo "OK"

#create web chroot dir
read -p "Input one path of virtualhost: " vir_path
mkdir -p ${vir_path}
echo "<h1>${domain_name}</h1>" >> ${vir_path}/index.html

#create virtualhost configure
create_vir ${domain_name} ${vir_path}
echo -e "\033[35mcreate virtualhost seccuseful\033[0m"

#create statuse dir
read -p "you need status dir ? Input yes|no : " ans1
if [ $ans1 == yes ] ; then
    create_status
    echo -e "\033[35mcreate staus dir seccuseful\033[0m"
fi

#create auth dir
read -p "you need authrization dir ? Input yes|no : " ans2
if [ $ans2 == yes ] ; then
    create_authdir ${domain_name} ${vir_path}
    echo -e "\033[35mcreate authrization dir seccuseful\033[0m"
fi

#create alias dir
read -p "you need alias dir ? Input yes|no : " ans3
if [ $ans3 == yes ] ; then
    create_aliasdir ${domain_name} ${vir_path}
    echo -e "\033[35mcreate alias dir seccuseful\033[0m"
fi


原創文章,作者:megedugao,如若轉載,請注明出處:http://www.www58058.com/50390

(0)
megedugaomegedugao
上一篇 2016-10-09 16:16
下一篇 2016-10-09 18:54

相關推薦

  • 第九周

    統計可登錄shell與不能登陸shell的個數 2. 寫一個腳本 3.寫一個腳本    4、寫一個腳本,完成如下功能 腳本能夠接受一個參數。 (1) 如果參數1為quit,則顯示退出腳本,并執行正常退出。 (2) 如果參數1為yes,則顯示繼續執行腳本。 (3) 否則,參數1為其它任意值,均執行非正常退出。    5、…

    Linux干貨 2016-12-26
  • bash特性及配置文件

    bash配置文件     兩類:         profile:為交互式登錄shell提供配置         bashrc:為非交互式登錄shell提供配置…

    Linux干貨 2016-08-31
  • 96-Mariadb-1

        一. MariaDB or MySQL基礎知識                   層次模型 –> 網狀模型 –> …

    2016-11-18
  • LNMP安裝過程中出現的問題及解決方法

    一、背景介紹    操作系統版本:centos6.8    nginx版本:nginx-1.10.2            mysql版本:mysql5.7.16    php版本:php5.6.28   由于mysql和php的…

    Linux干貨 2016-11-23
  • HA專題: corosync+pacemaker實現nginx高可用

    HA專題: corosync+pacemaker實現nginx高可用 前言 實驗介紹 實驗拓撲 實驗環境 實驗步驟 準備工作 安裝HA集群組件 安裝nginx和配置nfs 使用crmsh配置集群資源 測試 總結 前言 這幾天都會學習高可用集群, 也會將其中的一些實驗寫出來分享給大家, 這個專題估計會寫5篇左右, p.s: 寫博客很累的 實驗介紹 這次的實驗比…

    Linux干貨 2016-04-11
  • 用戶管理

    用戶管理 用戶通過uid來識別,用戶的uid是全局唯一,Linux用戶分三大類: 用戶類別可以分為 管理員 系統用戶 普通用戶 ——管理員的id為0,系統用戶的id為1-499,一般用戶的id為500- 組也是一樣(centos6.9和centos7.3 id編號有所不同)上述是centos6.9的id編號。 管理員賬戶:root,可…

    2017-06-01
欧美性久久久久