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
下一篇 2016-10-09

相關推薦

  • ftp的配置

    FTP服務器配置 VSFTP主配置文件路徑:/etc/vsftpd/vsftpd.conf,重要參數: anonymous_enable=yes/no 是否允許匿名用戶訪問 anon_upload_enable=yes/no 是否允許匿名用戶上傳文件 anon_mkdir_write_enable=yes/no 是否允許匿名用戶創建目錄 anon_other…

    2017-10-16
  • Linux入門之文本處理三劍客之grep

    Linux入門之文本處理三劍客之grep  文本處理工具:  grep,sed(流編輯器),awk    grep簡述及特點 簡介:全局搜索正則表達式出來的行并打印 (Global search REgular expression and Print out  the line),一種按照特定模式(patt…

    Linux干貨 2016-08-07
  • 搜索引擎的檢索模型-查詢與文檔的相關度計算

    1. 檢索模型概述       搜索結果排序時搜索引擎最核心的部分,很大程度度上決定了搜索引擎的質量好壞及用戶滿意度。實際搜索結果排序的因子有很多,但最主要的兩個因素是用戶查詢和網頁內容的相關度,以及網頁鏈接情況。這里我們主要總結網頁內容和用戶查詢相關的內容。     &nbsp…

    2015-12-10
  • Week1: Linux 初步

    1. 描述計算機的組成及其功能 一個完整的計算機系統由硬件系統和軟件系統兩大部分組成 馮諾依曼體系下的計算機五大部件 CPU:運算器、控制器、寄存器、緩存(一二三級緩存)) 存儲器:內存 RAM(Random-Access Memory) Input:輸入指令、提供數據 Output: 輸出數據加工后的結果 要點:計算機中的信息(程序和數據)以二進制方式表示…

    Linux干貨 2016-12-04
  • N26-博客作業-week2

    1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。   cp:copy 復制文件和路徑 cp [OPTION]… [-T] SOURCE DEST cp [OPTION]… SOURCE… DIRECTORY cp [OPTION]… -t DIRECTORY SOURCE&…

    Linux干貨 2017-02-12
  • N26-博客作業-week7

    1、創建一個10G分區,并格式為ext4文件系統;      (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;     ~]# fdisk /dev/sda Welcome to fdisk (util-li…

    Linux干貨 2017-03-19
欧美性久久久久