PHP Apache 配置虚拟主机

WBOY
Release: 2016-06-23 13:58:30
Original
829 people have browsed it

1.找到Apache的\conf目录下的httpd.conf文件,打开它,找到下面这两行:

# Virtual hosts

#Include conf/extra/httpd-vhosts.conf

把他前边的#号去掉,修改后如下如下:

# Virtual hosts

Include conf/extra/httpd-vhosts.conf

意思是启用虚拟主机的设置文件httpd-vhosts.conf,虚拟主机的设置都在这个文件下设置,不用去改httpd.conf,这样比较清晰。



2.找到Apache的\conf\extra目录下的httpd-vhost.conf这个文件。

打开它的时候里面已经含有像下面这样的内容:

?虚拟主机配置开始

ServerAdmin webmaster@dummy-host.localhost

DocumentRoot "E:/wamp/www/ecshop"//网站的根路径-虚拟主机的目录,即域名对应的根目录

ServerName "www.baidu.com"//虚拟主机域名-你想要的域名

ServerAlias www.dummy-host.localhost

ErrorLog "logs/dummy-host.localhost-error.log"

CustomLog "logs/dummy-host.localhost-access.log" common


还要在每个虚拟主机配置开始前加入以下内容:

//这是你的虚拟主机的被授权的目录一般与DocumentRoot “”?虚拟主机的目录,即域名对应的根目录相同。

Options Indexes FollowSymLinks Includes ExecCGI

AllowOverride All

Order allow,deny

Allow from all

Allow from all - 只要allow别人才行访问上面定义的目录,否则在IE或firefox访问时会显示503错误,即禁止访问。这是Apache默认的设置,最后一行是这样的

Deny from all意思是拒绝所有访问对根目录的访问,别人是访问不了你的网站的,

所以要想其他用户可以访问到你的项目就得改成

Allow from all

3.找到C:\WINDOWS\system32\drivers\etc目录下的hosts文件

加上一句下面的话

127.0.0.1 www.baidu.com?这个是你的域名,你要设置多少个虚拟主机,就要加多少行这样的记录。

=========================================================================================================
例子
<directory>Options Indexes FollowSymLinks Includes ExecCGIAllowOverride AllOrder allow,denyAllow from all</directory><virtualhost>ServerAdmin webmaster@dummy-host2.localhostDocumentRoot E:\wamp\www\ecshopServerName www.test.comErrorLog logs/dummy-host2.localhost-error_logCustomLog logs/dummy-host2.localhost-access_log common</virtualhost>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template