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.178linux.com/50390

(0)
megedugaomegedugao
上一篇 2016-10-09
下一篇 2016-10-09

相关推荐

  • 误删除centos6.8内核修复全过程

    关于误删除系统内核或内核损坏修复教程,本教程主要详细描述系统内核或内核损坏修复过程中步骤详解 一.操作环境 硬件:华硕笔记本 软件:VMware Workstation Pro 12版本  Centos 6.8.iso镜像 二,修复步骤 第一步,我们先要挂载centos6.8的镜像,然后光盘启动 进入系统救援模式 进入当前系统的根目录 我们需要手动…

    Linux干货 2016-09-05
  • N25-第四周作业

    1、复制/etc/skel目录为/home/tuse1,要求/home/tuse1及其内部文件的属组和其它用户均没有任何访问权限。   cp -r /etc/skel /home/tuser1;chmod go= /home/tuse1 2、编辑/etc/group文件,添加组hadoop    vi /et…

    Linux干货 2016-12-27
  • PHP中引用的详解(引用计数、写时拷贝)

    《PHP5中文手册》内容中"引用的解释"一文的摘要: 1. PHP中引用的特性 PHP中引用意味着用不同的名字访问同一个变量内容,引用不是C的指针(C语言中的指针里面存储的是变量的内容,在内存中存放的地址),是变量的另外一个别名或者映射。注意在 PHP 中,变量名和变量内容是不一样的,因此同样的内容可以有不同的名字。最接近的比喻是 Uni…

    Linux干货 2015-04-10
  • MBR详解

    前言:     话说,现在买电脑如果预装win8以上的系统,基本上都是GPT。想当年博主买的电脑预装的win8磁盘分区样式就是GPT,而且貌似如果想把win8换win7就得把GPT改成MPR。虽然会在最后提到GPT,不过本文还是主要讲解MBR,并通过实验验证。 机械硬盘: 主引导记录(Master Boot Record,缩写:MBR),…

    Linux干货 2016-11-14
  • DNS服务器类型及查询过程

    什么是DNS   DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串。通过主机名,最终得到该主机名对应的IP地址的过程叫做域名解析(或主机名解析)。 DNS域名称   域名系统作为一个层次结构和分布式数据库,包含各种类型的数据,…

    Linux干货 2017-02-08
  • 堡垒机-麒麟开源堡垒机苹果 Mac支持版本发布

      近日,麒麟开源堡垒机团队开发测试了支持Mac OS苹果操作系统的Web插件,苹果系统用户可以直接和Windows用户一样,登录到Web平台,使用点击的方式调动运维工具并且登录到目标系统进行操作运维。 Mac OS插件支持ssh、telnet、rdp、vnc、x11、sftp、ftp、应用发布等所有协议。   注:麒…

    Linux干货 2016-05-19