WAMP 似乎没有将 IP 地址更改为域

WAMP doesn't seem to be changing IP address to a domain

我正在尝试更改从 WAMP 服务器访问我的网站的方式。我可以像 xxx.xxx.xxx.xxx/name 一样访问它,是的,它工作得很好。我搜索了如何将 "xxx.xxx.xxx.xxx/name" 更改为像 www.name.com 这样的域名,我得到了一些结果,但其中 none 有效。这些是我所做的事情:

首先我去了我的主机文件

C:\Windows\System32\drivers\etc

,添加了一行“127.0.0.1 mytestdomain.com”,这是它的样子: host file

接下来,我将“#Include conf/extra/httpd-vhosts.conf”从 httpd.conf 更改为 "Include conf/extra/httpd-vhosts.conf",位于:

"D:\wamp64\bin\apache\apache2.4.27\conf"

.

最后,我添加了

<VirtualHost mytestdomain.com>
    DocumentRoot "D:/wamp64/www/myTestDomain/"
    ServerName mytestdomain.com
    ServerAlias mytestdomain.com
    <Directory "D:/wamp64/www/myTestDomain/">
        Order allow, deny
        Allow from all
    </Directory>
</VirtualHost>

在 "httpd-vhosts.conf" 位于:

"D:\wamp64\bin\apache\apache2.4.27\conf\extra"

哦,是的,这是在 myTestDomain 文件夹中:myTestDomain

完成所有这些后,我重新启动了 WAMP 并转到了我的主域,但它似乎没有工作,同时 "xxx.xxx.xxx.xxx/myTestDomain" 似乎正在工作。

您的 HOSTS 文件应如下所示

127.0.0.1  localhost
127.0.0.1  mytestdomain.com
::1  localhost
::1  mytestdomain.com

您的虚拟主机定义如下

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot D:/wamp64/www
    <Directory  "D:/wamp64/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "D:/wamp64/www/myTestDomain/"
    ServerName mytestdomain.com
    ServerAlias mytestdomain.com
    <Directory "D:/wamp64/www/myTestDomain/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

或者打开wampserver主页,使用Tools菜单下的Add a Virtual Hostlink,全部搞定你没看错。

NOTE: Using .com is a bad idea unless you actually intend to host your live site from your PC, instead use a .dev for example. Change the HOSTS file accordingly.

Bigger NOTE: Hosting a live site from a PC is a very bad idea. If you are using a desktop OS it is not configured to cope with more than 30 external connections so if your site gets even vaguely popular, users will get a terrible experience, most of them queuing for connections for page parts to be downloaded.