域名

站点目录

www.etiantian.org

/var/html/www

blog.etiantian.org

/var/html/blog

bbs.etiantian.org

/var/html/bbs

[root@httpd tools]# rpm -qa httpd

httpd-2.2.15-47.el6.centos.x86_64

[root@httpd tools]# rpm -e httpd-2.2.15-47.el6.centos.x86_64

warning: /etc/httpd/conf/httpd.conf saved as /etc/httpd/conf/httpd.conf.rpmsave

[root@httpd tools]# rpm -qa httpd

[root@httpd tools]# ls -sh httpd-2.2.27.tar.gz 

7.2M httpd-2.2.27.tar.gz

[root@httpd tools]# tar xf httpd-2.2.27.tar.gz 

[root@httpd tools]# cd httpd-2.2.27

[root@httpd httpd-2.2.27]# ls INSTALL README

INSTALL  README

[root@httpd httpd-2.2.27]# yum -y install zlib zlib-devel

[root@httpd httpd-2.2.27]# ./configure --prefix=/application/apache2.2.27 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite

[root@httpd httpd-2.2.27]# echo $?

0

[root@httpd httpd-2.2.27]# make

[root@httpd httpd-2.2.27]# make install

[root@httpd httpd-2.2.27]# ln -s /application/apache2.2.27/ /application/apache

[root@httpd httpd-2.2.27]# cd

[root@httpd ~]# /application/apache/bin/apachectl -t

httpd: apr_sockaddr_info_get() failed for httpd

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Syntax OK

[root@httpd ~]# /application/apache/bin/apachectl start

httpd: apr_sockaddr_info_get() failed for httpd

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

[root@httpd ~]# lsof -i :80

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

httpd   76147   root    4u  IPv6  77976      0t0  TCP *:http (LISTEN)

httpd   76149 daemon    4u  IPv6  77976      0t0  TCP *:http (LISTEN)

httpd   76150 daemon    4u  IPv6  77976      0t0  TCP *:http (LISTEN)

httpd   76151 daemon    4u  IPv6  77976      0t0  TCP *:http (LISTEN)

[root@httpd ~]# /etc/init.d/iptables stop

[root@httpd ~]# setenforce 0

setenforce: SELinux is disabled

[root@httpd ~]# cd /application/apache/conf/

[root@httpd conf]# ll

total 92

-rw-r--r-- 1 root root 53011 Oct 26 21:17 mime.types

-rw-r--r-- 1 root root 12958 Oct 26 21:17 magic

drwxr-xr-x 3 root root  4096 Oct 26 21:17 original

-rw-r--r-- 1 root root 13658 Oct 26 21:17 httpd.conf

drwxr-xr-x 2 root root  4096 Oct 26 21:17 extra

过滤出生效的配置文件:

[root@httpd conf]# egrep -v "#|^$" httpd.conf 

ServerRoot "/application/apache2.2.27"

Listen 80

User daemon

Group daemon

ServerAdmin [email protected]

DocumentRoot "/application/apache2.2.27/htdocs"

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

    Deny from all

    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

    DirectoryIndex index.html

    Order allow,deny

    Deny from all

    Satisfy All

ErrorLog "logs/error_log"

LogLevel warn

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

    LogFormat "%h %l %u %t \"%r\" %>s %b" common

   

      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

   

    CustomLog "logs/access_log" common

    ScriptAlias /cgi-bin/ "/application/apache2.2.27/cgi-bin/"

    AllowOverride None

    Options None

    Order allow,deny

    Allow from all

DefaultType text/plain

    TypesConfig conf/mime.types

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

SSLRandomSeed startup builtin

SSLRandomSeed connect builtin

[root@httpd conf]# cd extra/

[root@httpd extra]# pwd

/application/apache/conf/extra

[root@httpd extra]# ls -l

total 56

-rw-r--r-- 1 root root  2859 Oct 26 21:17 httpd-autoindex.conf

-rw-r--r-- 1 root root  1753 Oct 26 21:17 httpd-dav.conf

-rw-r--r-- 1 root root  2344 Oct 26 21:17 httpd-default.conf

-rw-r--r-- 1 root root  1103 Oct 26 21:17 httpd-info.conf

-rw-r--r-- 1 root root  5078 Oct 26 21:17 httpd-languages.conf

-rw-r--r-- 1 root root   949 Oct 26 21:17 httpd-manual.conf

-rw-r--r-- 1 root root  3789 Oct 26 21:17 httpd-mpm.conf

-rw-r--r-- 1 root root  2207 Oct 26 21:17 httpd-multilang-errordoc.conf

-rw-r--r-- 1 root root 11530 Oct 26 21:17 httpd-ssl.conf

-rw-r--r-- 1 root root   817 Oct 26 21:17 httpd-userdir.conf

-rw-r--r-- 1 root root  1507 Oct 26 21:17 httpd-vhosts.conf

创建网站根目录

[root@httpd extra]# mkdir /var/html/{www,blog,bbs} -p

[root@httpd extra]# tree /var/html/                  

/var/html/

|-- bbs

|-- blog

`-- www


3 directories, 0 files

创建网站首页html

[root@httpd extra]# touch /var/html/{www,blog,bbs}/index.html

[root@httpd extra]# tree /var/html/

/var/html/

|-- bbs

|   `-- index.html

|-- blog

|   `-- index.html

`-- www

    `-- index.html


3 directories, 3 files

[root@httpd extra]# for name in www blog bbs;do echo "http://$name.etiantian.org" >/var/html/$name/index.html;done

[root@httpd extra]# for name in www blog bbs;do cat /var/html/$name/index.html;done                           

http://www.etiantian.org

http://blog.etiantian.org

http://bbs.etiantian.org

[root@httpd extra]# cp httpd-vhosts.conf httpd-vhosts.conf_bak

修改虚拟主机配置文件

[root@httpd extra]# vim httpd-vhosts.conf

#

# Virtual Hosts

#

# If you want to maintain multiple domains/hostnames on your

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so the server doesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.

#

# Please see the documentation at 

#

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.


#

# Use name-based virtual hosting.

#

NameVirtualHost *:80


#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any block.

#

    ServerAdmin [email protected]

    DocumentRoot "/var/html/www"

    ServerName www.etiantian.org

    ServerAlias etiantian.org

    ErrorLog "logs/www-error.log"

    CustomLog "logs/www-access_log" common

    ServerAdmin [email protected]

    DocumentRoot "/var/html/blog"

    ServerName blog.etiantian.org

    ErrorLog "logs/blog-error.log"

    CustomLog "logs/blog-access_log" common

    ServerAdmin [email protected]

    DocumentRoot "/var/html/bbs"

    ServerName bbs.etiantian.org

    ErrorLog "logs/bbs-error.log"

    CustomLog "logs/bbs-access_log" common

"httpd-vhosts.conf" 50L, 1503C written

修改主配置文件:添加下面内容                                                      

[root@httpd extra]# tail -6 ../httpd.conf

    Options FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

语法检查:

[root@httpd extra]# /application/apache/bin/apachectl -t  

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Syntax OK

重载服务:

[root@httpd extra]# /application/apache/bin/apachectl graceful

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName