标签:apache apache配置 apache安装及其配置 apache安装方法 apache配置文件详解
一、实验安装环境
系统:CentOS6.6-i686
软件:httpd-2.2.31.tar.gz
关闭防火墙:/etc/init.d/iptables stop
关闭selinux:setenforce 0
二、Apache简介及其安装
1.Apache简介
Apache是web服务软件,提供http服务。
2.Apache的特点
简单、速度快、应用广泛,主要是应用于静态小文件。
apache结合php可以实现动态。
3.Apache下载及其编译安装
yum -y install zlib zlib-devel
wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz
tar xf httpd-2.2.31.tar.gz
cd httpd-2.2.31
./configure \
--prefix=/application/apache2.2.31 \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm-worker \
--enable-rewrite
make && make install
启动Apache: /apalication/apache/bin/apachectl start
检查是否启动:lsof -i :80
报错解决方法:
[root@lamp01 extra]# ../../bin/apachectl -t
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
vi conf/httpd.conf 找servername 加上如下:
#ServerName www.example.com:80
ServerName 127.0.0.1:80
完成上诉步骤后Apache安装成功。
三、测试是否成功
在浏览器中输入本系统环境的ip,看到 It works !即代表安装成功。。。
四、apache主配置文件详解
[root@lamp01 conf]# vi httpd.conf
ServerRoot "/application/apache2.2.31"
Listen 80 ---监听的端口
<IfModule !mpm_netware_module>
User daemon
Group daemon
</IfModule>
DocumentRoot "/application/apache2.2.31/htdocs"---站点根目录
<Directory /> ---权限控制/
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all ---拒绝所有
</Directory>
<Directory "/application/apache2.2.31/htdocs">
Options Indexes FollowSymLinks --
AllowOverride None
Order allow,deny
Allow from all ---允许所有
</Directory>
<IfModule dir_module>---指定访问首页配置文件。
DirectoryIndex index.html
</IfModule>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog "logs/error_log" ---错误日志
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i
\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent
}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/application/apache2.2.31/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/application/apache2.2.31/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
DefaultType text/plain
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
虚拟主部署机:
部署多个站点,每个站点希望用不同的域名和站点目录,或者不同的端口、不同的IP,则需要虚拟主机的功能。
一个http服务配置多个站点,就需要多个虚拟主机
虚拟主机的分类:
1.基于域名(本文主要讲解这个)
2.基于端口
3.基于IP
域名 站点目录
www.chen.com /var/html/www
bbs.chen.org /var/html/bbs
blog.chen.org /var/html/blog
1)创建站点目录
mkdir -p /var/html/{www,bbs,blog}
2)向里面写入index.html
for name in www blog bbs; do echo "http://$name.chen.com">/var/html/$name/index.html; done
[root@lamp01 conf]# tree /var/html/
/var/html/
├── bbs
│ └── index.html
├── blog
│ └── index.html
└── www
└── index.html
3 directories, 3 files
[root@lamp01 conf]#
3)查看里面内容信息
for name in www blog bbs; do cat /var/html/$name/index.html; done
4)打开Apache主配置文件把Include conf/extra/httpd-vhosts.conf前面的#号去掉
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
5)打开/application/apache/conf/extra/httpd-vhosts.conf配置文件,做如下修改
#www.chen.com vhosts
<VirtualHost *:80>
ServerAdmin 1297212044@qq.com
DocumentRoot "/var/html/www"
ServerName www.chen.com
ServerAlias chen.com
ErrorLog "logs/www-error_log"
CustomLog "logs/www-access_log" common
</VirtualHost>
#bbs.chen.com vhosts
<VirtualHost *:80>
ServerAdmin 1297212044@qq.com
DocumentRoot "/var/html/bbs"
ServerName bbs.chen.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
#blog.chen.com vhosts
<VirtualHost *:80>
ServerAdmin 1297212044@qq.com
DocumentRoot "/var/html/blog/"
ServerName blog.chen.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
配置完成后检查语法和平滑重启:
/application/apache/bin/apachectl -t
/application/apache/bin/apachectl graceful
6)在windows中的hosts文件中做解析
10.0.0.6 ww.chen.com bbs.chen.com blgo.chen.com
7)输入域名则即可实现访问。
本文出自 “叫醒你的不是闹钟而是梦想” 博客,请务必保留此出处http://purify.blog.51cto.com/10572011/1772656
标签:apache apache配置 apache安装及其配置 apache安装方法 apache配置文件详解
原文地址:http://purify.blog.51cto.com/10572011/1772656