一. 配置跳转
说明:
只有在启动时带上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>
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com