![](/img/trans.png)
[英]Switching between Htdoc Webroots - Change my “DocumentRoot” variable in “httpd.conf” or use Symbolic Links?
[英]Are there cmd prompts to quickly change httpd.conf DocumentRoot directories
我在文件夹中有多个网站,我需要来回切换。 每次我都要去httpd.conf文件找到它们并更改DocumentRoot
和Directory
行。 我想知道是否有更快的方法来执行此操作,可能是使用cmd
提示符? 或者也许我可以创建一个php
inc
文件。
谢谢。
将所有网站设置为Virtual Hosts
会更好。 它们总是可用的,您不必更改除URL之外的任何内容来单独访问每个URL。
HowTo:在WAMP中创建虚拟主机
在做任何事情之前,请确保APACHE和MYSQL正常工作!
在wamp目录结构之外创建一个新文件夹。 例如
C:\websites\www
但这可以在运行wamp的PC可见的任何磁盘驱动器上
在c:\\ sites中为要创建的每个站点创建一个子文件夹。 例如:
C:\websites\www\site1
C:\websites\www\site2
编辑文件C:\\ wamp \\ bin \\ apache \\ apachex.yz \\ conf \\ extra \\ httpd-vhosts.conf其中x,y和z是您实际安装的apache的版本号。
注意:如果要在两个或更多版本的apache之间切换,则必须依次对所有版本的apache进行此操作。
建议:我喜欢使用格式sitename.dev让我明白我正在处理我的网站的localhost开发副本,你可能更喜欢另一种表示法,没关系,在这种情况下,单词dev没有实际定义的含义,它只是我命名我的开发版本的实时网站的方式。
注意:删除或更好地注释掉(使用第1列中的#)此文件中已存在的行。 它们只是一个例子。
示例内容:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
## must be first so the the wamp menu page loads when you use just localhost as the domain name
## Also NEVER change the security to anything other than Allow from 127.0.0.1 localhost ::1
## Then a drive by Ip address hack should return a 403 denied access
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
**Using Apache 2.2 syntax**
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
## For every ip in the subnet, just use the first 3 numbers of the subnet
## Check you actual subnet for the actual values to use here
Allow from 192.168.0
</Directory>
**Using Apache 2.4 syntax**
<Directory "C:/wamp/www">
Require local
## And possibly allow access from you local network
## Check you subnet for the actual values to use here
Require ip 192.168.0
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/websites/www/site1"
ServerName site1.dev
ServerAlias www.site1.dev
Options Indexes FollowSymLinks
**Using Apache 2.2 syntax**
<Directory "C:/websites/www/site1">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.nnn
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
# If you want to allow access to everyone
#Allow from all
</Directory>
**Using Apache 2.4 syntax**
<Directory "C:/websites/www/site1">
AllowOverride All
Require local
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Require ip 192.168.0.nnn
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Require ip 192.168.0
# If you want to allow access to everyone
#Require all granted
</Directory>
</VirtualHost>
添加所需数量,以便每个站点都有一个,根据需要更改DocumentRoot,ServerName和任何其他参数。
这也允许您对配置进行SITE SPECIFIC更改。
注意:这将使wamp管理器“Put Online”功能不再对这些新的vhost'ed站点产生任何影响,因为每个站点的安全性现在都是vhost定义的一部分,因此请离开WAMP,OFFLINE。
如果要将一个或多个站点联机,则必须在httpd-vhosts.conf文件中手动更改“允许命令”。
要检查子网,请执行以下操作:启动命令窗口,然后运行
>ipconfig
在输出中查找“Default Gateway”行,并在Allow命令中使用第三个数字。
编辑您的httpd.conf文件并搜索这些行,它们位于文件的底部。
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
删除此行上的“#”注释字符以包含新更改的vhost,这将导致apache注册它们的存在。 例如
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
在编辑httpd.conf文件时仍在搜索
# onlineoffline tag - don't remove
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
不要改变这些线!
在<\\ Directory>标记后添加以下内容以保护新的C:\\ websites文件夹。
<Directory "C:/websites/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
这是为了在新目录结构上设置安全性,以便只允许从127.0.0.1(localhost)访问这些新站点,除非在特定VHOST中进行修改。 PS您的内部网络可能类似于192.168.xy,请先检查您的系统!
现在,为了让您的浏览器知道如何访问这些新域名,例如site1.dev和site2.dev,我们需要告诉Windows它们所在的IP地址。 有一个名为HOSTS的文件是域名服务器(DNS)发明前几天的宿醉。 这是一种为IP地址提供简单易记的名称的方法,这当然是DNS服务器现在为我们所做的事情。
编辑你的HOSTS文件,这可以在C:\\ windows \\ system32 \\ drivers \\ etc中找到,该文件没有扩展名。
Windows保护此文件,因此您必须是管理员才能保存对此文件的更改。
如果您使用的是VISTA或Windows7 / 8,您可能会认为您是管理员,但您不是!
因此,要编辑此文件,您必须以特定方式启动编辑器或记事本以获得管理员权限。 要执行此操作,请找到您的编辑器图标并使用以下击键启动它:
Shift +右键单击其图标,将显示一个菜单,单击“以管理员身份运行”项,然后在将出现的挑战对话框上单击“允许”。
现在您已准备好编辑hosts文件,因此将编辑器导航到c:\\ windows \\ system32 \\ drivers \\ etc \\ hosts
将以下行添加到此文件中
127.0.0.1 site1.dev 127.0.0.1 site2.dev
注意:您需要在此文件中为每个新虚拟主机添加一行。
保存这些更改后,您需要让Windows刷新其“域名 - ipaddress交叉引用”缓存。
要执行此操作,请以管理员身份启动命令窗口(Shift +左键单击命令窗口图标)并运行这两个命令。
>net stop "DNS Client"
>net start "DNS Client"
注意:引号是必需的,因为服务名称中有空格。
为了让Apache获取这些更改,您必须反弹(重启)apache。
请执行此操作:Wamp manager - > Apache - > Service - > Restart Service
您现在应该可以在浏览器中使用地址site1.dev来访问新网站。 如果您已经对站点进行了编码,则将站点代码复制到“C:/ websites / xxxx”文件夹中,或者将快速简单的index.php文件放入“c:\\ websites \\ xxxx”文件夹中以证明其一切正常。 例:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>SITE1</title>
</head>
<body>
<?php
echo '<div style="background-color:red;color;white;text-align:center;font-size:18px">HELLO FROM Site1</div>';
?>
</body>
</html>
故障排除:
如果您使用了新域名(site1.dev)并且未找到该站点。 一种。 检查hosts文件的更改。 湾 重新启动在Windows中运行的“DNS服务”。 这会缓存您在浏览器中使用的所有doman名称,以便每次重新使用域名时浏览器都不必查询DNS服务器。 这可能已经缓存了你失败的尝试,但重启很容易,应该解决问题,并且更快启动窗口,这也应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.