Apache源码安装、基于域名虚拟机测试

1、   安装wget、gcc、lynx(httpd2.4在centos6上安装依赖包)

yum -y install wget gcc gcc-c++ expat expat-devel openssl-devel lynx

2、   安装apr(由于httpd2.4需要apr1.4版本及以上)

wget -c -P /src  http://mirror.bit.edu.cn/apache/apr/apr-1.6.2.tar.gz

tar zxvf /src/apr-1.6.2.tar.gz -C /src

cd /src/apr-1.6.2

./configure --prefix=/usr/local/apr

make&&make install

3、   安装apr-util(由于httpd2.4需要apr1.4版本及以上)

wget -c -P /src   http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.0.tar.gz

tar zxvf /src/apr-util-1.6.0.tar.gz -C /src

cd /src/apr-util-1.6.0

./configure --prefix=/usr/local/apr-util    -with-apr=/usr/local/apr

make&&make install

4、   安装pcre

wget -c -P /src   https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz

tar zxvf /src/pcre-8.41.tar.gz -C /src

cd /src/pcre-8.41

./configure --prefix=/usr/local/pcre

make&&make install

5、   安装httpd(源码安装)

wget -c -P /src  https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.28.tar.gz

wget -c -P /src http://mirrors.sohu.com/apache/httpd-2.4.28.tar.gz

tar zxvf /src/httpd-2.4.28.tar.gz -C /src

cd /src/httpd-2.4.28

./configure --prefix=/usr/local/apache    --enable-so  --enable-rewrite   --enable-ssl --with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util  --with-pcre=/usr/local/pcre

--enable-so 开启动态库

--enable-rewrite 开启rewrite规则

--enable-ssl  启用https

make

make install

6、   配置apache为系统服务

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

centos7下需要做以下配置:

编辑vim /etc/init.d/httpd在#!/bin/sh下添加以下配置:

#chkconfig: 234570 70

#description:apache

   

chkconfig –add httpd

这样就可以使用systemctl start|stop|status httpd.service 命令启动|停止|状态

7、   启动apache(需配置httpd.conf中ServerName)

service httpd start

查看端口监听和进程情况

netstat -antp | grep httpd

ps -ef | grep httpd

8、   配置Apache虚拟主机

开启虚拟主机配置,注释掉httpd.conf中Include conf/extra/httpd-vhosts.conf

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

<VirtualHost*:80>

    ServerAdmin admin@asiainfo.com

    DocumentRoot "/usr/local/apache/htdocs/test1"

    ServerName www.test1.com

    #ServerAlias www.test.example.com

    ErrorLog "logs/test1.error_log"

    CustomLog "logs/test1.access_log"common

<Directory"/usr/local/apache/htdocs/test1">

                   Order allow,deny

                   Allow from all

         </Directory>

</VirtualHost>

 

<VirtualHost*:80>

    ServerAdmin admin@asiainfo.com

    DocumentRoot "/usr/local/apache/htdocs/test2"

    ServerName www.test2.com

    ErrorLog "logs/test2.error_log"

    CustomLog "logs/test2.access_log"common

<Directory"/usr/local/apache/htdocs/test2">

                   Order allow,deny

                   Allow from all

         </Directory>

</VirtualHost>

9、   创建发布目录,写入测试页面

mkdir -p /usr/local/apache/htdocs/{test1,test2}

echo "This is test1 page" >/usr/local/apache/htdocs/test1/index.html

echo "This is test2 page" >/usr/local/apache/htdocs/test2/index.html

10、重启apache、关闭selinux、iptables

service httpd restart

service iptables stop

setenforce 0

11、测试机上添加hosts

vi /etc/hosts

192.168.241.133 www.test1.com

192.168.241.133 www.test2.com

测试:

curl www.test1.com

curl www.test2.com

12、虚拟主机配置文件详细参数

<VirtualHost *:80>

ServerAdmin admin@asiainfo.com 管理员邮箱地址

    DocumentRoot "/usr/local/apache/htdocs/test1" 发布目录

    ServerName www.test1.com 域名

    ErrorLog "logs/test1.error_log" 错误日志

CustomLog "logs/test1.access_log" common 正常日志

<Directory "/usr/local/apache/htdocs/test2">

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

Order allow,deny  默认禁止所有客户端访问

Order deny,allow  默认允许所有客户端访问

Allow from all    允许所有客户端访问


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值