WAMP的虚拟主机不工作 [英] WAMP Virtual Host not working

查看:163
本文介绍了WAMP的虚拟主机不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是WAMP 2.5版
我的Apache是​​2.4.9
PHP:5.5.12
MySQL的:5.6.17

I am using a wamp version 2.5 My Apache is 2.4.9 PHP: 5.5.12 MySQL: 5.6.17

我有以下配置:

在我的的httpd.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

在我的 G:\\ WAMP \\ BIN \\ apache的\\ apache2.4.9 \\的conf \\额外\\的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 \\等\\主机

# 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/ BUT 我得到一个未找到服务器错误我试图使用它访问 www.mysite.dev 的http:// mysite的.dev ,但仍然有一个糟糕的运气!

I try to access my project using this URL: http://www.mysite.dev/ BUT I am getting a Server not found error I tried accessing it using www.mysite.dev , http://mysite.dev but still having a bad luck!

我的虚拟主机是以前的工作,但我不知道为什么它不工作了。有些怪异的东西怎么回事。

My virtual host was working before but i'm not sure why it wasn't working now. Some weird stuff going on.

我不知道发生了什么。任何想法将大大AP preciated!

I am not sure what's happening. Any ideas will be greatly appreciated!

谢谢!

推荐答案

首先,你需要删除的例子虚拟从您的虚拟主机,httpd.conf文件的定义。他们在那里为示例只只是为了让您开始使用的语法,而不应保持活动的conf /额外/的httpd-vhosts.conf 因为它们都指向不存在的文件夹中。

First you need to remove the example dummy definitions from your vhost-httpd.conf file. They are there as examples only just to get you started with the syntax, and should not remain in an active conf/extra/httpd-vhosts.conf as they are pointing to non existant folders.

因此​​,从文件中删除这两个定义:

So remove these 2 definitions from the file:

<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>

二阿帕奇2.4.x的是IPV4(127.0.0.1)和IPV6(:: 1)知道让你的主机文件看起来应该像这样与IPv4和定义IPV6版本为每个站点。该浏览器可以任意使用或者让你既需要,但可能会使用在preference IPv6网络到​​IPv4如果都是您的PC上实际活跃。

Second Apache 2.4.x is IPV4 ( 127.0.0.1 ) and IPV6 (::1) aware so your hosts file should look like this with definitions for both IPV4 and IPV6 versions for each site. The browser can arbitrarily use either so you need both but will probably use the IPV6 network in preference to the IPV4 if both are actually active on your PC.

127.0.0.1   localhost
::1  localhost

127.0.0.1   mysite.dev
::1  mysite.dev

现在的实际存在系统上的2虚拟主机试图以此为虚拟主机定义:

Now on the 2 Virtual Hosts that actually exist on your system try this as the Virtual Host definition :

<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>

&LT;目录&GT; ...&LT; /目录&GT; &LT内部分;虚拟主机&GT; ...&LT; /虚拟主机&GT; 部分告诉Apache是​​哪个IP地址被允许接受连接,因此使用Apache 2.4语法要求本地限制访问,以便只有PC运行WAMPServer即Apache可以连接到这些网站。

The <Directory>....</Directory> section within the <VirtualHost>....</VirtualHost> section tells Apache which IP Addresses it is allowed to accept connections from, so using the Apache 2.4 syntax Require local limits access so that only the PC running WAMPServer i.e. Apache can connect to any of these site.

避免在同一个定义混合Apache 2.2的语法和Apache 2.4语法在一起。所以不要用

Avoid mixing Apache 2.2 syntax and Apache 2.4 syntax together in the same definition. So dont use

Order Allow,Deny
Allow from all

Require all granted

中相同的定义。您正在使用的Apache 2.4所以使用Apache 2.4的语法。

in the same definition. You are using Apache 2.4 so use the Apache 2.4 syntax.

如果你找到你要允许其它电脑的本地网络里面看到你的网站,即工作伴侣或孩子等,您可以将此语法添加到一个或多个虚拟主机的定义。

If you find you want to allow other PC's inside your local network to see you site i.e. work mate or the kids etc, you can add this syntax to one or more of your Virtual Host definition.

允许只是一个单一的其它PC到您的网站

Allow just a single other PC into your site

Require local
Require ip 192.168.1.100

2,或其他电脑

or 2 other PC's

Require local
Require ip 192.168.1.100, 192.168.1.101

或本地网络上的任何人只要用4四分位数的IP地址的前3。

Or to anyone on your local network just use the first 3 of the 4 quartiles of the ip address.

Require ip 192.168.1

此外,还要避免使用,允许从任何地方访问即语法。

Also avoid using the syntax that allows access from anywhere i.e.

Require all granted  <--Apache 2.4 syntax

or 

Order Allow,Deny     <-- Apache 2.2 syntax
Allow from all    

这可以解决您的问题,在短期内,但只是在等待,当你决定你想显示你的网站给朋友/客户/老板的某个时候抓住你后。如果你让世界被允许进入你的网络得到端口转发路由器你的舞台,将导致所有的网站以成为提供给世界。

更好的改变一个虚拟主机定义你希望人们能看到测试/从吹牛要求当地要求所有授予的一个网站,只允许单个站点是来自Internet的访问。

Better to change the ONE Virtual Host Definition for the ONE site you want people to see for testing/bragging from Require local to Require all granted and only allow that single site to be access from the internet.

一旦你所做的所有这些改变记得重新启动Apache。

Once you have made all these changes remember to restart Apache.

此外,如果你更改hosts文件,使chnages活跃,你要么重新启动或从命令窗口的命令行运行这些命令启动伊辛的运行作为管理员选项​​。

Also if you change the hosts file to make the chnages active you should either reboot or run these command from the command line of a command windows started ising the Runs as Administrator option.

net stop dnscache
net start dnscache

这篇关于WAMP的虚拟主机不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆