------------------------------------分隔线---------------------------------------
二、centos7使用httpd2.4基于域名构建httpd服务
centos7上的httpd-2.4基本同centos6上的httpd2.2一样,所有有的地方就不详细的说明和操作了。
1、安装httpd服务
yum -y install httpd
2、创建网页及储存路径
mkdir -p /data/vhost/www{1,2}
echo "centos7 www1" > /data/vhost/www1/index.html
echo "centos7 www2" > /data/vhost/www2/index.html
3、建立虚拟主机www1并且做相应的限制等
[root@linuxidc ~]# vim /etc/httpd/conf.d/vhost1.conf
<VirtualHost 192.168.1.104:80>
DocumentRoot /data/vhost/www1
ServerName www1.magedu.com
CustomLog /var/log/httpd/www1/acess_log common
ErrorLog /var/log/httpd/www1/err_log
<Directory "/data/vhost/www1">
Options None
AllowOverride None
##定义访问权限:
<RequireAll>
Require all granted
Require not ip 192.168
</RequireAll>
</Directory>
####定义状态页面并且认证
<Location "/server-status">
SetHandler server-status
Require all granted
AuthType Basic
AuthName "admin"
AuthUserFile "/etc/httpd/.htpasswd"
Require valid-user
</Location>
</VirtualHost>4、建立虚拟主机www2
[root@linuxidc ~]# vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost 192.168.1.104:80>
DocumentRoot /data/vhost/www2
ServerName www2.magedu.com
CustomLog /var/log/httpd/www2/acess_log common
ErrorLog /var/log/httpd/www2/err_log
<Directory "/data/vhost/www2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
----------------------------------分隔线-----------------------------------------
三、centos6编译安装httpd-2.4基于域名构建httpd服务
由于httpd-2.4所依赖的apr和apr-until需要1.4版本以上。而centos默认自带的版本比较低,所以我们在centos6使用httpd-2.4的时候需要我们手动进行编译安装才可以:
准备工具:apr-1.4.6.tar
apr-util-1.4.1.tar
httpd-2.4.6.tar
1、安装开发包组件
[root@linuxidc ~]# yum -y install prce-devel[root@linuxidc ~]# yum groupinstall Development tools Server Platform Development2、安装apr
[root@linuxidc ~]# tar xf apr-1.4.6.tar.bz2
[root@linuxidc ~]# cd apr-1.4.6
[root@linuxidc apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@linuxidc apr-1.4.6]# make && make install3、安装apr-until
[root@linuxidc ~]# tar xf apr-util-1.4.1.tar.bz2
[root@linuxidc ~]# cd apr-util-1.4.1
[root@linuxidc apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@linuxidc apr-util-1.4.1]# make && make install4、编译安装httpd2.4
[root@linuxidc ~]# tar xf httpd-2.4.6.tar.bz2
[root@linuxidc ~]# cd httpd-2.4.6
[root@linuxidc httpd-2.4.6]# ./configure --prefix=/usr/local/apache24 --sysconfdir=
/etc/httpd24 --enable-so --enable--ssl --enable-cgi --enable-rewrite --with-zlib
--with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
--enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@linuxidc ~]# make && make install5、启动服务查查看下监听端口
[root@linuxidc ~]# /usr/local/apache24/bin/apachectl start
[root@linuxidc ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::53263 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::80 :::*6、开启虚拟主机模块编辑配置文件去除#即可
[root@linuxidc ~]# vim /etc/httpd24/httpd.conf
Include /etc/httpd24/extra/httpd-vhosts.conf ##启用此项7、配置虚拟主机
[root@linuxidc ~]# vim /etc/httpd24/extra/httpd-vhosts.conf