Apache学习笔记
apache吧
全部回复
仅看楼主
level 1
晓_弥彦 楼主
1.查看Apache版本号
httpd -v
2013年01月23日 06点01分 1
level 1
晓_弥彦 楼主
2.Apache服务控制
(1)启动Apache服务
httpd -k start
(2)重新启动Apache服务
httpd -k restart
(3)停止Apache服务
httpd -k stop
or
httpd -k shutdown
2013年01月23日 08点01分 2
level 1
晓_弥彦 楼主
3.基于主机名的多IP虚拟主机配置
(1)httpd.conf配置文件中加入下列配置信息:
NameVirtualHost 192.168.1.102:80
<VirtualHost 192.168.1.102:80>
ServerName www.domain1.dawn
ServerAlias domain1.dawn *.domain1.dawn
DocumentRoot /www/domain1
</VirtualHost>
<VirtualHost 192.168.1.102:80>
ServerName www.domain2.dawn
ServerAlias domain2.dawn *.domain2.dawn
DocumentRoot /www/domain2
</VirtualHost>
NameVirtualHost 192.168.1.103:80
<VirtualHost 192.168.1.103:80>
ServerName bbs.domain1.dawn
ServerAlias forum.domain1.dawn
DocumentRoot /www/domain1_bbs
</VirtualHost>
<VirtualHost 192.168.1.103:80>
ServerName bbs.domain2.dawn
ServerAlias forum.domain2.dawn
DocumentRoot /www/domain2_bbs
</VirtualHost>
(2)测试
输入http://www.domain1.dawn,访问/www/domain1服务目录
输入http://domain2.dawn,访问/www/domain2服务目录
输入http://bbs.domain1.dawn,访问/www/domain1_bbs服务目录
输入http://forum.domain1.dawn,访问/www/domain1_forum服务目录
输入http://news.domain2.dawn,访问/www/domain2.dawn服务目录
输入http://www.domain3.dawn,访问/www/domain1服务目录
(3)说明
①在配置完成httpd.conf文件后,须确保所有域名及IP信息已在DNS服务器中完成相关映射
②在<VirtualHost>标签对中可以添加几乎所有属性指令,系统先匹配<VirtualHost>标签对中的指令,无匹配项时再从主服务器及全局环境中匹配
③此例中,对于domain3.dawn(DNS服务器中映射的IP为:192.168.1.102)此类未定义的域名信息,将会自动匹配至与它具有相同IP地址的第一个虚拟主机中(此时域名不匹配,如上面的例子访问的是/www/domain1服务目录)
④此例中,若要访问主服务器,可以使用http://localhost或http://127.0.0.1访问,或者是除192.168.1.102及192.168.1.103以外的IP(如果还有其他IP的话)或已在DNS服务器中映射过其他IP并指向此服务器的域名进行访问
2013年01月23日 09点01分 3
补充: (1)*.domain.dawn不包含domain.dawn域名信息 (2)当同一IP组中两个以上的<VirtualHost>标签对中存在相同域名信息时,系统不会报错,自动匹配第一个与之匹配的<VirtualHost>标签对 (3)此贴中如未特别说明,均为在Apache2.2中做的配置测试
2013年01月23日 10点01分
level 1
晓_弥彦 楼主
4.访问控制
# 策略:先拒绝,再允许;本例仅授权本机访问
Order deny,allow
Deny from all
Allow from 127.0.0.1
# 策略:先允许,再拒绝;本例拒绝来自本机的访问
Order allow,deny
Allow from all
Deny from 127.0.0.1
2013年01月28日 08点01分 5
level 1
晓_弥彦 楼主
5.重定向
Redirect [status] URL-path URL
作用域:server config, virtual host, directory, .htaccess
覆盖项:FileInfo
状态:基本(B)
模块:mod_alias
在虚拟主机www.domain1.dawn的<VirtualHost>或<Directory>标签对中加入以下指令:
Redirect / http://www.domain2.dawn/
则当访问http://www.domain1.dawn/index.html时,访问请求将被重定向至http://www.doamin2.dawn/index.html
注:
(1)[status]用于返回HTTP状态码
(2)Redirect优先级高于Alias和ScriptAlias
2013年01月30日 10点01分 7
[status]: (1)永久定向:permanent|301 (2)临时定向:temp|302 (3)参见定向:seeother|303 (4)已废弃:gone|410
2013年01月30日 10点01分
回复 晓_弥彦 :status为410时将忽略URL参数,即应该在指令中删除URL参数。
2013年01月30日 11点01分
回复 晓_弥彦 :状态变化情况参见access.log
2013年01月30日 11点01分
level 1
晓_弥彦 楼主
6.作用域
server config:
可用于服务器配置文件(httpd.conf),但不能用于任何<VirtualHost>、<Directory>段及.htaccess文件中
virtual host:
可用于<VirtualHost>段中
directory:
可用于<Directory>、<Location>、<Files>、<Proxy>段中
.htaccess:
可用于针对单个目录及其子目录的.htaccess文件,.htaccess文件的使用需开启overrides相应指令支持方可使用
2013年01月30日 11点01分 9
level 1
晓_弥彦 楼主
7.配置段容器
相关模块:
core
mod_version
mod_proxy
相关指令:
<IfDefine>
<IfModule>
<IfVersion>
<Directory>
<DirectoryMatch>
<Files>
<FilesMatch>
<Location>
<LocationMatch>
<Proxy>
<ProxyMatch>
(1)条件配置段容器
<IfDefine>、<IfModule>、<IfVersion>只在Web服务器启动和重新启动时起作用。
(2)常规配置段容器
<Directory>、<DirectoryMatch>、<Files>、<FilesMatch>一起作用于文件系统,<Location>、<LocationMatch>一起作用于网络空间,<Proxy>、<ProxyMatch>一起作用于代理服务器访问。
2013年02月01日 02点02分 10
level 1
晓_弥彦 楼主
8.配置段合并
(1)<Directory>和.htaccess同时处理
(2)<DirectoryMatch>和<Directory ~>同时处理
(3)<Files>和<FilesMatch>同时处理
(4)<Location>和<LocationMatch>同时处理
说明:
(1)当请求是由mod_proxy处理时,<Proxy>容器将会在处理顺序中取代<Directory>容器的位置
(2)<Directory>容器使用短目录优先的规则进行应用(即按字典顺序由短到长依次处理),其他配置段按它们在配置文件中出现的顺序依次被处理
(3)<VirtualHost>容器中的配置段在外部对应的段处理完毕后再处理,这样就允许虚拟主机覆盖主服务器的设置
(4)用Include指令包含进来的配置被视为按原样插入到Include指令所在的位置
(5)配置处理自动继承到下一级子目录
(6)处理顺序中位于后面的段将覆盖前面的段的相应配置项
举例:
目录结构如下:
-domain1
 test.php
 index2.php
 .htaccess
 -test
  test.php
  index2.php
  -test_sub
   test.php
   index2.php
   -test_sub_sub
    test.php
    index2.php
 -test2
  test.php
  index2.php
  .htaccess
 -test3
  test.php
  index2.php
httpd.conf部分配置段信息如下:
<VirtualHost 192.168.1.102:80>
    ServerName www.domain1.dawn
    ServerAlias domain1.dawn *.domain1.dawn
    DocumentRoot /www/domain1
    <Location /test/test_sub>
        # H 允许对/test/test_sub网络空间的访问
        Order deny,allow
        Deny from all
        Allow from all
    </Location>
    <Directory D:/AppServ/www/domain1/test>
        # B 允许Indexes指令覆盖
        Options None
        AllowOverride Options=Indexes
        Order deny,allow
        Deny from all
        Allow from all
        <Files test.php>
            # F 允许访问/www/domain1/test其子目录中的test.php文件
            Order deny,allow
            Deny from all
            Allow from all
        </Files>
    </Directory>
    <Directory D:/AppServ/www/domain1>
        # A 允许Order、Indexes指令覆盖
        Options None
        AllowOverride Limit Options=Indexes
        Order deny,allow
        Deny from all
        Allow from all
        <Files test.php>
            # E 拒绝访问/www/domain1目录及其子目录中的test.php文件
            Order deny,allow
            Deny from all
        </Files>
    </Directory>
    <Files test.php>
        # D 允许访问/www/domain1目录及其子目录中的test.php文件
        Order deny,allow
        Deny from all
        Allow from all
    </Files>
    <Location /test>
        # I 拒绝对/test网络空间的访问
        Order deny,allow
        Deny from all
    </Location>
    # J 允许对/test/test_sub/test_sub_sub网络空间的访问
    Include "conf/test.conf"
</VirtualHost>
<Files test.php>
    # C 拒绝对test.php文件的访问
    Order deny,allow
    Deny from all
</Files>
<Location /test/test_sub>
    # G 拒绝对/test/test_sub网络空间的访问
    Order deny,allow
    Deny from all
</Location>
conf/test.conf配置段信息如下:
<Location /test/test_sub/test_sub_sub>
Order deny,allow
Deny from all
Allow from all
</Location>
/www/domain1/下.htaccess配置段信息如下:
# 开启目录列表功能
Options Indexes
Order deny,allow
Deny from all
Allow from all
/www/domain1/test2/下.htaccess配置段信息如下:
# 关闭目录列表功能
Options None
Order deny,allow
Deny from all
Allow from all
配置段的合并处理顺序为:A->B->C->D->E->F->G->H->I->J
合并处理结果:
(1)/及/test3网络空间具有目录列表功能
(2)允许使用HTTP协议访问以下文件:
/www/domain1/index2.php
/www/domain1/test/test_sub/test_sub_sub/index2.php
/www/domain1/test/test_sub/test_sub_sub/test.php
/www/domain1/test2/index2.php
/www/domain1/test3/index2.php
2013年02月01日 12点02分 13
当使用URL:http://www.domain1.dawn/test3访问服务器空间时,配置文件会动态加载/www/domain1目录下及其所有子目录下的.htaccess,动态合并配置后再按照配置段合并顺序处理配置。
2013年02月01日 12点02分
level 9
LZ 这些httpd.conf 里面内容 怎么我看到的 都是放在 sites-available 目录下 某个文件的 是放在哪里 都可以么 能重复么
2013年02月25日 19点02分 14
level 1
晓_弥彦 楼主
用Include指令可以将.conf放在任意目录中。在不同目录中可以存在同名文件。
2013年02月26日 00点02分 15
1