Apache 虚拟主机(子域)访问 LAN 上的不同计算机
我目前正在尝试配置 Apache HTTP Server 的虚拟主机(子域),以便可以使用 LAN 上的另一台计算机访问它。 Apache 与 PHP 和 MySQL 的当前设置在同一台物理机器上本地运行。
因此,我有两个虚拟主机设置(开发和 cms)在非默认端口 50080 上运行。服务器计算机的 IP 为 10.0.0.10。从同一台物理机,我可以使用以下命令访问两个虚拟主机:
development.localhost:50080
cms.localhost:50080
从不同的物理机,我可以使用以下命令访问服务器的根目录:
10.0.0.10:50080
但我不能或不知道如何从不同的计算机访问虚拟主机。我尝试过类似的方法:
development.10.0.0.10:50080
cms.10.0.0.10:50080
但它们似乎不起作用。
我的 httpd-vhosts
文件如下所示:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin [email protected]
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
我阅读了此处和 Apache 论坛的其他一些帖子,但没有确切的案例。
我想知道如何从另一台计算机访问虚拟主机(子域)并保留相同的端口(如果可能)。
提前致谢
I am currently trying to configure the Virtual Host (Subdomain) of my Apache HTTP Server so it can be accessed with another computer on my LAN. The current setup of Apache with PHP and MySQL works locally on the same physical machine.
So I have two Virtual Host setup (development and cms) running on a non-default port of 50080. The machine of the server have a IP of 10.0.0.10. From the same physical machine, I can access the two Virtual Host using:
development.localhost:50080
cms.localhost:50080
From a different physical machine, I can access the root of the server using:
10.0.0.10:50080
But I cannot or do not know how to access the Virtual Host from the different machine. I tried something like:
development.10.0.0.10:50080
cms.10.0.0.10:50080
But they do not seem to work.
Here's how my httpd-vhosts
file looks like:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin [email protected]
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
I read some of the other post here and the Apache forum, but there's not exact case for this.
I was wondering how I can access the Virtual Host (Subdomain) from another machine and keep the same port if possible.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我明白了,如果其他人正在寻找这个,这里是配置:
================================= =================================================== =
==================================================== ===================================
从第二台机器,您应该能够使用“alias”和“development.alias”进行访问
Ok, I figured it out, here are the configuration if anyone else is looking for this:
==================================================================================
==================================================================================
From the second machine, you should be able to access with "alias" and "development.alias"
我建议进行以下更改(添加 ServerAlias 行):
重新启动 Apache 以确保更改生效。
然后,在您的第二台计算机上,您需要为这些新域名添加自定义 dns 条目。如果是Windows,则编辑文件
c:\windows\system32\drivers\etc\hosts
。如果是Linux,则编辑/etc/hosts。无论哪种方式添加:现在在您的第二台计算机上您应该能够访问以下 URL:
I suggest making the following change (add the ServerAlias lines):
Restart Apache to ensure the changes take effect.
Then on your second computer you need to add a custom dns entry for these new domain names. If it is Windows, edit the file
c:\windows\system32\drivers\etc\hosts
. If it is Linux, edit /etc/hosts. Either way add:Now on your second computer you should be able to access the following URLs:
除非我遗漏了什么,否则您需要设置 DNS 条目,或者将条目添加到访问服务器的每台计算机的 /etc/hosts 文件中。
localhost
是默认存在于每个人的 /etc/hosts 文件中的一个条目,始终指向 127.0.0.1。如果不添加 /etc/hosts 条目,则developer.localhost
不存在,并且使用子域作为 IP 地址前缀根本不起作用。Unless I'm missing something, you'll need to either set up DNS entries, or add entries to the /etc/hosts file of each computer accessing the server.
localhost
is an entry that exists in everyone's /etc/hosts file by default, always pointing to 127.0.0.1. Without adding a /etc/hosts entry,developer.localhost
doesn't exist, and prefixing an ip address with a subdomain won't work at all.使用 SSH + Putty 隧道,因此我的服务器上有 127.0.0.1,我通过在服务器端执行以下操作来设法访问我的子域:
我没有更改远程计算机的主机文件,它的工作方式就像魅力
Using a SSH + Putty tunnel, and thus having a 127.0.0.1 on my server, I managed to access my subdomains by doing the following on my server side:
I did not change the host file of the remote computer, and it works like a charm
对于
命名虚拟主机
,您需要使用主机名或域名来连接到您的 apache 服务器。它不适用于 ip。您可以在第二个系统上的
/etc/hosts
中插入一个条目。For
Named Virtual Hosts
you need to use a hostname or domainname to connect to you apache server. It does not work with ips.You could insert an entry in your
/etc/hosts
on your second system.