Bobby

导航

【Web】Apache安装及配置

一、获取软件包

# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.31.tar.gz

二、安装依赖包

# yum -y install zlib zlib-devel gcc
# yum -y groupinstall "Development Tools"

三、Apache安装

1. 解压并安装

# tar zxvf httpd-2.2.31.tar.gz
# cd httpd-2.2.31
# rpm -e httpd-tools-2.2.15-47.el6.centos.1.x86_64
# ./configure --prefix=/usr/local/apache --enable-deflate --enable-expires --enable-headers --enable-modules-most --enable-so --with-mpm-worker --enable-rewrite
# echo $?
# make 
# make install

2. 启动服务

# /usr/local/apache/bin/apachectl -t
# /usr/local/apache/bin/apachectl start

3. 验证服务状态

# lsof -i :80
# netstat -na|grep 80
# ps -ef |grep http

四、Apache配置及站点

1. 修改配置文件

# cd /usr/local/apache/conf
# vi httpd.conf
   ServerAdmin hanboyi@sfsctech.com
   ServerName 127.0.0.1:80
   <Directory "/usr/local/apache/htdocs">
        Options -Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
   </Directory>
   Include conf/extra/httpd-vhosts.conf

2. 安装cronolog工具

# cd /root/tools
# tar zxvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure
# make && make install

 3. 添加虚拟主机

# vi /usr/local/apache/conf/extra/httpd-vhosts.conf
   NameVirtualHost *:80
   <VirtualHost *:80>
         ServerAdmin <xxx@xxx.com>
         DocumentRoot "/usr/local/apache/htdocs/www"
         ServerName xxx.xxx.com
         ServerAlias xxx.com
         ErrorLog "logs/www_error_log"
         CustomLog "|/usr/local/sbin/cronolog /app/logs/www_access_%Y%m%d.log" combined
   </VirtualHost>

   <VirtualHost *:80>
         ServerAdmin <xxx@xxx.com>
         DocumentRoot "/usr/local/apache/htdocs/bbs"
         ServerName xxx.com
         ErrorLog "logs/bbs_error_log"
         CustomLog "|/usr/local/sbin/cronolog /app/logs/bbs_access_%Y%m%d.log" combined
   </VirtualHost>

   <VirtualHost *:80>
       ServerAdmin <xxx@xxx.com>
       DocumentRoot "/usr/local/apache/htdocs/blog"
       ServerName xxx.com
       ErrorLog "logs/blog_error_log"
       CustomLog "|/usr/local/sbin/cronolog /app/logs/blog_access_%Y%m%d.log" combined
   </VirtualHost>

4. 创建站点目录

# for file in `ls /usr/local/apache/htdocs/`; do echo "Welcome to the $file site." >/usr/local/apache/htdocs/$file/index.html; done
# for file in `ls /usr/local/apache/htdocs/`; do ll /usr/local/apache/htdocs/$file; done
# for file in `ls /usr/local/apache/htdocs/`; do cat /usr/local/apache/htdocs/$file/index.html; done

5. 验证并重启服务

# /usr/local/apache/bin/apachectl -t
# /usr/local/apache/bin/apachectl graceful

6. 验证站点

# curl http://aaa.test.com
# curl http://bbb.test.com
# curl http://ccc.test.com

 

posted on 2019-06-04 10:51  youth315  阅读(149)  评论(0)    收藏  举报