在 win7 的 apache 服务器上创建虚拟服务器时遇到挑战(解析主机名)

发布于 2024-10-04 11:54:29 字数 2513 浏览 4 评论 0原文

我在我的便携式 Windows 7 机器上安装了一个 apache 服务器,使用 xampp 作为接口。我一直在与一些人在 irc 频道上合作,但很快就要睡觉了,而且回复速度越来越慢。

我将以下代码添加到我的 httpd.conf 文件中:

#virtual servers
#Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName localhost.MEALS
    DocumentRoot C:\xampp\htdocs\MEALS
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.HA
    DocumentRoot C:\xampp\htdocs\Hackers
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.WIK
    DocumentRoot C:\xampp\htdocs\WhoIKnow
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.TUS
    DocumentRoot C:\xampp\htdocs\Unity
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.PHP
    DocumentRoot C:\xampp\htdocs\phpMyAdmin
    DirectoryIndex index.php
</VirtualHost>

并且我有以下配置:

Setting environment for using XAMPP for Windows.
John@ASSIMILATER C:\xampp
# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:80)
*:80                   is a NameVirtualHost
         default server localhost.MEALS (C:/xampp/apache/to which there was conf/httpd.conf:512)
         port 80 namevhost localhost.MEALS (C:/xampp/apache/conf/httpd.conf:512)
         port 80 namevhost localhost.HA (C:/xampp/apache/conf/httpd.conf:516)
         port 80 namevhost localhost.WIK (C:/xampp/apache/conf/httpd.conf:520)
         port 80 namevhost localhost.TUS (C:/xampp/apache/conf/httpd.conf:524)
         port 80 namevhost localhost.PHP (C:/xampp/apache/conf/httpd.conf:528)
Syntax OK

John@ASSIMILATER C:\xampp
#

但是,当我尝试在 Web 浏览器中访问 localhost.PHP 时,它告诉我找不到服务器。我被指示需要解析我的计算机上的主机名。我被引导到一些 irc 频道(dns 和 windows),但没有回复。我搜索了谷歌并浏览了这个网站:http://technet.microsoft。 com/en-us/library/bb727005.aspx#EEAA。我不太确定我正在阅读的内容,并且据我所知,它并没有给我关于在哪里解析主机名或要编辑的文件的明确指示。

目前默认服务器也是代码中的顶级虚拟服务器。我想调用 localhost 并显示我创建的一个简单的 html 页面,该页面位于“htdocs/index.html”中,它将导航到其他服务器(指向“localhost.PHP”等的链接)。有没有办法让默认服务器保持“localhost”,它指向“htdocs/index.html”,同时维护其他虚拟服务器,或者我必须创建另一个虚拟服务器并将其设为默认服务器?

任何和所有的帮助表示赞赏。

编辑:我有人帮助我在我的计算机上找到 HOSTS 文件,但无法编辑它。我关闭了所有防病毒功能,关闭了间谍机器人(UAC 始终关闭,并且我始终以管理员权限运行),特别是右键单击 np++ editpadlite 和 Windows 记事本,并且只能在记事本中编辑,但需要使用不同的名字。

I have an apache server installed on my portable windows 7 machine using xampp as an interface. I've been working with a few people on an irc channel but must soon go to bed and replies are getting slower.

I have the following code added to my httpd.conf file:

#virtual servers
#Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName localhost.MEALS
    DocumentRoot C:\xampp\htdocs\MEALS
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.HA
    DocumentRoot C:\xampp\htdocs\Hackers
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.WIK
    DocumentRoot C:\xampp\htdocs\WhoIKnow
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.TUS
    DocumentRoot C:\xampp\htdocs\Unity
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost.PHP
    DocumentRoot C:\xampp\htdocs\phpMyAdmin
    DirectoryIndex index.php
</VirtualHost>

And I have the following configuration:

Setting environment for using XAMPP for Windows.
John@ASSIMILATER C:\xampp
# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:80)
*:80                   is a NameVirtualHost
         default server localhost.MEALS (C:/xampp/apache/to which there was conf/httpd.conf:512)
         port 80 namevhost localhost.MEALS (C:/xampp/apache/conf/httpd.conf:512)
         port 80 namevhost localhost.HA (C:/xampp/apache/conf/httpd.conf:516)
         port 80 namevhost localhost.WIK (C:/xampp/apache/conf/httpd.conf:520)
         port 80 namevhost localhost.TUS (C:/xampp/apache/conf/httpd.conf:524)
         port 80 namevhost localhost.PHP (C:/xampp/apache/conf/httpd.conf:528)
Syntax OK

John@ASSIMILATER C:\xampp
#

However when I try to access localhost.PHP in my web browser it tells me the server is not found. I was instructed that I need to resolve the host names on my machine. I was directed to a few irc channels (dns and windows) to which there was no reply. I searched google and ran across this site: http://technet.microsoft.com/en-us/library/bb727005.aspx#EEAA. I'm not quite sure what I'm reading and as near as I can tell it doesn't quite give me a clear instruction on where to resolve the host name or a file to edit.

Also currently the default server is the top virtual server in the code. I would like to call localhost and show a simple html page I created which is in "htdocs/index.html" which will navigate to the other servers (links pointing to "localhost.PHP" etc). is there a way to have the default server remain "localhost" which points to "htdocs/index.html" while maintaining the other virtual servers, or will I have to create another virtual server and make that the default?

Any and all help appreciated.

edit: I had someone help me find the HOSTS file on my machine but am unable to edit it. I turned off all antivirus features, turned off spybot (UAC was always off and I always run with administrator privileges) specifically right clicked on np++ editpadlite and windows notepad and was only able to edit in notepad, but was required to save the file with a different name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千仐 2024-10-11 11:54:29

您必须以管理员身份显式运行记事本(无论 UAC 设置如何),并且在保存时,请确保选择“所有文件”而不是默认的 *.txt。

当我尝试在 W7 上编辑主机文件时,我发现了同样的事情,但似乎仅作为计算机上的管理员与以管理员身份显式运行程序并不完全相同。

You have to explicitly run Notepad as an administrator (regardless of UAC settings) and when you go to save, make sure you select 'all files' rather than the default *.txt.

I found the same thing when I tried to edit the hosts file on W7, but it seems that just being an administrator on the machine isn't quite the same as explicitly running the program as an administrator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文