我正在使用 wamp 版本 2.5我的阿帕奇是 2.4.9菲律宾比索: 5.5.12MySQL: 5.6.17
我有这些配置:
在我的httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
在我的G:'wamp'bin'apache'apache2.4.9'conf'extra'httpd-vhost.conf
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "g:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "g:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "g:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "g:'wamp'www'mysite'public"
ServerName mysite.dev
</VirtualHost>
在我的c:'Windows'System32'Drivers'etc'hosts
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
127.0.0.1 mysite.dev
# ::1 localhost
我尝试使用此 URL 访问我的项目:http://www.mysite.dev/
但是我遇到了一个Server not found error
,我尝试使用 www.mysite.dev
访问它,http://mysite.dev
但仍然运气不好!
我的虚拟主机以前在工作,但我不确定为什么它现在不起作用。一些奇怪的事情正在发生。
我不确定发生了什么。任何想法将不胜感激!
谢谢!
首先,您需要从 vhost-httpd.conf 文件中删除示例虚拟定义。它们仅作为示例存在,只是为了帮助您开始使用语法,并且不应保留在活动conf/extra/httpd-vhosts.conf
中,因为它们指向不存在的文件夹。
因此,请从文件中删除以下 2 个定义:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "g:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "g:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
第二个Apache 2.4.x是IPV4(127.0.0.1(和IPV6(::1(感知的,因此您的hosts
文件应如下所示,每个站点的IPV4和IPV6版本都有定义。浏览器可以任意使用其中任何一个,因此您需要两者,但如果两者都在您的 PC 上实际处于活动状态,则可能会优先使用 IPV6 网络而不是 IPV4。
127.0.0.1 localhost
::1 localhost
127.0.0.1 mysite.dev
::1 mysite.dev
现在,在系统上实际存在的 2 个虚拟主机上,尝试将其作为虚拟主机定义:
<VirtualHost *:80>
DocumentRoot "g:/wamp/www"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
<Directory "G:/wamp/www">
AllowOverride All
Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "g:'wamp'www'mysite'public"
ServerName mysite.dev
ServerAlias www.mysite.dev
ErrorLog "logs/mysite-error.log"
CustomLog "logs/mysite-access.log" common
<Directory "G:/wamp/www/mysite/public">
AllowOverride All
Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
<VirtualHost>....</VirtualHost>
部分中的<Directory>....</Directory>
部分告诉Apache允许它接受来自哪些IP地址的连接,因此使用Apache 2.4语法Require local
限制访问,以便只有运行WAMPServer的PC即Apache可以连接到这些站点中的任何一个。
避免在同一定义中混合使用 Apache 2.2 语法和 Apache 2.4 语法。所以不要使用
Order Allow,Deny
Allow from all
和
Require all granted
在相同的定义中。您使用的是 Apache 2.4,因此请使用 Apache 2.4 语法。
如果您发现要允许本地网络中的其他PC查看您的站点,即同事或孩子等,则可以将此语法添加到一个或多个虚拟主机定义中。
只允许一台其他 PC 进入您的网站
Require local
Require ip 192.168.1.100
或 2 台其他电脑
Require local
Require ip 192.168.1.100, 192.168.1.101
或者对于本地网络上的任何人,只需使用 IP 地址的 4 个四分位数中的前 3 个。
Require ip 192.168.1
还要避免使用允许从任何地方访问的语法,即
Require all granted <--Apache 2.4 syntax
or
Order Allow,Deny <-- Apache 2.2 syntax
Allow from all
它可能会在短期内解决您的问题,但当您决定要向朋友/客户/老板展示您的网站时,它只是在等待稍后的某个时候抓住您。如果您进入端口转发阶段,您的路由器,以便允许世界进入您的网络,这将导致您的所有站点都可供世界使用。
最好将您希望人们看到的用于测试/吹嘘的站点的 ONE 虚拟主机定义从Require local
更改为Require all granted
,并且只允许从 Internet 访问该单个站点。
完成所有这些更改后,请记住重新启动Apache。
此外,如果您更改主机文件以使chnages处于活动状态,则应重新启动或从命令窗口的命令行运行这些命令,以开始使用Runs as Administrator
选项。
net stop dnscache
net start dnscache
如果您使用的是 Windows 10,则上述 dns 命令不再有效,您应该改为执行此操作。
ipconfig /flushdns
由于谷歌收购了.dev gTLD,拥有.dev开发网站不再容易,最好的缓解方法是将您的开发域重命名为.local或您喜欢的名称。
后台发生的情况是,本地 DNS 服务器将浏览器重定向到 127.0.53.53(打开 cmd> nslookup yourdomain.dev(,以便通知最终用户正在收购 .dev gTLD。由于主机文件中的 .dev 域设置为 127.0.0.1,因此显示连接被拒绝。
您可以在主机文件中将 127.0.0.1 更改为 127.0.53.53,并看到浏览器错误从 ERR_CONNECTION_REFUSED 更改为ERR_ICANN_NAME_COLLISION。
以下内容对我有用
<VirtualHost *:80>
DocumentRoot "G:'project'test.dev"
ServerAdmin test@gmail.com
ServerName test.dev
ErrorLog "logs/test.dev-error.log"
CustomLog "logs/test.dev-access.log" common
<Directory "G:'project'test.dev">
AllowOverride All
Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
我通过在 Apache 文件夹中的 httpd.conf 中取消注释某些行来解决同样的问题。
取消以下注释行:
Include conf/extra/httpd-vhosts.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so
保存文件并重新启动您的Apache,它将起作用。非常感谢这个人:https://john-dugan.com/wamp-vhost-setup/
我来得很晚,我做了@RiggsFolly提到的所有事情,但我改变了一件事,让它立即工作。我.dev
更改为.test
,因为保留了 .dev。希望这有帮助
查看 httpd.conf 中未注释的模块
- proxy_module
- proxy_http_module
在你apache httpd.config文件上试试这个:
<VirtualHost *:80>
ServerName mysite.dev
DocumentRoot "g:'wamp'www'mysite'public"
SetEnv APPLICATION_ENV "development"
<Directory "g:'wamp'www'mysite'public">
DirectoryIndex index.php
Options All Includes Indexes
Options All Indexes FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
重新启动您的 WAMP 服务器,并在您的浏览器上放置像 mysite.dev/这样的 URL。希望它能帮助你。谢谢。