现在需要安装apache2.2.4
过程如下 编译:安装目录为--prefix=/usr/local/apache22
./configure --prefix=/usr/local/apache22 --with-layout=apache --enable-module=so --enable-module=setenvif --enable-module=rewrite --with-mpm=prefork --enable-ssl 安装
make
make install
在安装了apache2.2.4之后,直接启动,会报有关ServerName的警告,但是还是可以启动的.通过客户端访问看到的默认页面是一句话 it works
在配置文件中修改如下:
#ServerName www.example.com:80
ServerName 127.0.0.1
就不会报错了
修改网站主目录如下
#DocumentRoot "/usr/local/apache22/htdocs"
DocumentRoot "/var/www/html"
访问的时候会报错
403 禁止访问
您无权查看该网页
您可能没有权限用您提供的凭据查看此目录或网页
例如在网站的主目录/var/ww/html下有1.html.在客户端访问http://IP/1.html就会报这个错.
解决办法:
<Directory />
Options FollowSymLinks
AllowOverride None
# Order deny,allow
# Deny from all
Order allow,deny
Allow from all
</Directory>
分析错误原因
查看配置文件httpd.conf,相关部分内容如下:
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
# 首先配置的缺省的限制,这个限制是非常严格的
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow 次序是先拒绝,再允许
Deny from all 默认是拒绝所有
</Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#从这里开始你必须指定允许启用特定的功能,如果某些不能正常工作,需要查看你是否已经启用了它.
#
# This should be changed to whatever you set DocumentRoot to.
#这里应该改为你设的DocumentRoot
<Directory "/usr/local/apache22/htdocs"> 可以看到这里是对缺省的主目录的设置
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#控制谁能访问这个网站
Order allow,deny 顺序是先允许再拒绝
Allow from all 默认是允许所有
</Directory>
所以缺省状态下只是对默认的主目录/usr/local/apache22/htdocs设的是允许所有访问,而对于其他的目录,采用默认的设置是拒绝所有访问的.
所以我们之前做的修改
<Directory />
Options FollowSymLinks
AllowOverride None
# Order deny,allow
# Deny from all
Order allow,deny
Allow from all
</Directory>
是将默认的限制调大了,让默认对所有的目录都允许所有人访问.或许会带来安全威胁.
安全的做法是按照文档说的
# This should be changed to whatever you set DocumentRoot to.
#这里应该改为你设的DocumentRoot
<Directory "/usr/local/apache22/htdocs"> 把它改为你设的主目录
启动以后就可以正常访问了.
启用虚拟主机配置
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf
编辑配置文件目录下的/extra/httpd-vhosts.conf
[iyunv@server1 extra]# vi 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
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# 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 <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
#
# 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
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# 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 <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/s1
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
启动报错
[iyunv@server1 conf]# ../bin/httpd -k start
httpd: Syntax error on line 54 of /usr/local/apache22/conf/httpd.conf: API module structure `php5_module' in file /usr/local/apache22/modules/libphp5.so is garbled - perhaps this is not an Apache module DSO?
唉,失败了.(个人觉得如果是相同版本的apache应该是可以的copy使用的,但未测试)