apache 配置学习笔记(一)

一. 配置跳转

说明:

   只有在启动时带上IfDefine后面配置的值作为启动脚本参数,配置才会生效 

 

配置:

 

<IfDefine ToGoogle>
Redirect / http://www.google.com/ 
</IfDefine> 

 

运行和结果:

 

Apache2.2\bin>httpd.exe -DToGoogle

 当访问http://ServerName:port/时,将跳转到google

 

 

二. 目录和文件

 

说明:

 

  限制目录和文件访问

 

配置:

 

<Directory "D:\Program Files\Apache2.2\htdocs\test">
    #Options Indexes FollowSymLinks
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all

<Files test.htm>
Order allow,deny
Deny from all
</Files>

</Directory>

 

 

运行结果:

 

   test 及子目录都无法访问,且目录下test.htm文件名的文件都无法访问

 

 

 

三. VirtualHost 基于域名的虚拟主机

 

配置: 

 

 

NameVirtualHost *

<VirtualHost *>
   ServerAdmin  you@example.com
   DocumentRoot /usr/local/apache2/htdocs
   ServerName localhost
   ErrorLog  /usr/local/apache2/logs/error_log
  TransferLog  /usr/local/apache2/logs/access_log
</VirtualHost>

<VirtualHost *>
   ServerAdmin  you@example.com
   DocumentRoot /usr/local/apache2/htdocs
   ServerName www.sefer.com
   ErrorLog  /usr/local/apache2/logs/error_log
  TransferLog  /usr/local/apache2/logs/access_log
</VirtualHost> 

<VirtualHost *>
   ServerAdmin sefer@xiaofeng.com
   DocumentRoot /usr/local/apache2/htdocs/sefer
   ServerName www.test.com
   ErrorLog logs/test.sefer.com-error_log
  TransferLog logs/test.sefer.com-access_log
</VirtualHost>
 

 

 

   绑定host :

       192.168.1.101 www.sefer.com www.test.com

   bin/apachectl -S 可以查看httpd.conf配置结果,bin/apachectl -t 可以查看配置httpd.conf语法是否正确;

 

运行结果:   

 

   通过 www.sefer.com www.test.com 分别取自各自目录的默认初始文件;

 

 

四. 默认访问文件 

 

 <IfModule dir_module>

DirectoryIndex index.html </IfModule>

 

 五. RewriteEngine

 

 默认是不安装的,安装如下:

   httpd-2.2.14/modules/mappers$ sudo /usr/local/apache2/bin/apxs -i -a -c mod_rewrite.c

 

 

   <VirtualHost *>

   ServerAdmin sefer@xiaofeng.com

   DocumentRoot /usr/local/apache2/htdocs/sefer

   ServerName www.test.com

   ErrorLog logs/test.sefer.com-error_log

   TransferLog logs/test.sefer.com-access_log

   RewriteEngine On

   RewriteRule /test/(.*) /index.html [R,L]

   RewriteRule /out/(.*) http://www.163.com [R,L]

</VirtualHost>

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值