首页 > 开发 > Apache > 正文

Apache中Virtual Host虚拟主机配置及rewrite参数说明

2020-04-16 19:29:39
字体:
来源:转载
供稿:网友

Virtual Host配置过程

这里例子中我们的路径为这样
DocumentRoot: /home/jb51 /sites/demo.Cuoxin.com
ServerName:demo.Cuoxin.com

1.进入apache虚拟主机设置目录

cd /etc/apache2/sites-available

2.创建文件demo.Cuoxin.com

<VirtualHost *:80> ServerAdmin webmaster@localhost DirectoryIndex index.html index.php DocumentRoot /home/jb51 /sites/demo.Cuoxin.com ServerName demo.Cuoxin.com ServerAlias demo.Cuoxin.com <Directory "/home/jb51 /sites/demo.Cuoxin.com"> allow from all Options + Indexes </Directory> </VirtualHost>


3.激活虚拟主机配置

sudo a2ensite demo.Cuoxin.com


4.进入 /etc/apache2/sites-enabled/目录,可以查看所有激活的虚拟主机。可以用 sudo a2dissite demo.Cuoxin.com 注销

cd /etc/apache2/sites-enabled ls -lt

显示 

复制代码 代码如下:

lrwxrwxrwx 1 root root 36 2013-04-05 17:29 demo.Cuoxin.com -> ../sites-available/demo.Cuoxin.com 

 
5.重启apache服务

sudo /etc/init.d/apache2 restart


6.ubuntu 设置host

vim /etc/hosts

 

127.0.0.1 demo.Cuoxin.com

 
7.<Directory>设置开启.htaccess与显示目录结构列表

<Directory "/home/jb51 /demo.Cuoxin.com"> AllowOverride none AllowOverride all Options -Indexes FollowSymLinks </Directory>

AllowOverride none 表示关闭.htaccess,如要开启可设置为AllowOverride all
Options -Indexes 表示关闭目录结构显示,如要开启可设置为 Options Indexes
Options FollowSymLinks 表示支持symbol link(软连接),如要关闭可设置为Options -FollowSymLinks

rewrite模块重要参数说明

开启rewrite:

sudo a2enmod rewrite

停用rewrite:

sudo a2dismod rewrite

服务器环境变量:Apache提供给rewirte模块的环境变量大概分成5个类型.

第一部分: HTTP headers 部分参数

1.参数名称: HTTP_USER_AGENT
样例参考值: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8
说明: 相当于PHP中的服务器参数: $_SERVER["HTTP_USER_AGENT"]

2.参数名称: HTTP_REFERER
样例参考值: http://www.test.cn/test.php
说明: 相当于PHP中的服务器参数: _SERVER["HTTP_REFERER"]

3.参数名称: HTTP_COOKIE
样例参考值: ZDEDebuggerPresent=php,phtml,php3
说明: 相当于PHP中的服务器参数: $_SERVER["HTTP_COOKIE"]

4.参数名称: HTTP_FORWARDED

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表