[Apache] 2.2与2.4版本在设置虚拟域名时的小差别

Apache服务器配置虚拟步骤:

1.在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.conf中写入如下配置:

#LoadModule vhost_alias_module modules/mod_vhost_alias.so   //开启虚拟服务扩展,去掉前面的#

#Include conf/extra/httpd-vhosts.conf  //包含虚拟域名配置文件,也可以在httpd.conf中直接配置,或者不固定其路径,比如以下文件

(Include conf/vhosts.conf)

 

2、在包含进来的虚拟域名配置文件中配置具体的域名信息:

apache 2.2版本
<VirtualHost *:80>
      DocumentRoot "D:/workspace/example"
      ServerName www.example.com
      <Directory "D:/workspace/example">
         Options Indexes FollowSymLinks
         AllowOverride All
         Order allow,deny
         Allow from all
      </Directory>
</VirtualHost>
apache 2.4版本
<VirtualHost *:80>
      DocumentRoot "D:/workspace/example"
      ServerName Api.rrt.com
      <Directory "D:/workspace/example">
         Options +Indexes +FollowSymLinks +ExecCGI
         AllowOverride All
         Order allow,deny
         Allow from all
         Require all granted
      </Directory>
</VirtualHost>

 

3、修改本地hosts文件,将虚拟域名映射到127.0.0.1

127.0.0.1  www.example.com

 

4、大功告成,重启Apache服务器,在浏览器测试www.example.com,便可以看到自己开发的网站了

 

posted @ 2015-10-22 14:07  燃烧小火苗  阅读(577)  评论(0编辑  收藏  举报