Apache 虚拟主机(子域)访问 LAN 上的不同计算机

发布于 2024-11-30 17:08:15 字数 1231 浏览 1 评论 0原文

我目前正在尝试配置 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 技术交流群。

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

发布评论

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

评论(5

时光倒影 2024-12-07 17:08:15

好吧,我明白了,如果其他人正在寻找这个,这里是配置:

================================= =================================================== =

机器 A(Apache HTTP 服务器):
httpd-虚拟​​主机:

NameVirtualHost *:50080

<VirtualHost *:50080>
    DocumentRoot "C:/www/HTTP"
    ServerName localhost
    ServerAlias alias <!-- Added -->
</VirtualHost>

<VirtualHost *:50080>
    ServerAdmin [email protected]
    DocumentRoot "C:/www/HTTP/development"
    ServerName development.localhost
    ServerAlias development.phoenix <!-- Added -->
    ErrorLog "logs/development.localhost-error.log"
    CustomLog "logs/development.localhost-access.log" common
</VirtualHost>

主机:

127.0.0.1 development.localhost

127.0.0.1 alias
127.0.0.1 development.alias

==================================================== ===================================

机器 B(访客机器):
主持人:

10.0.0.10 alias
10.0.0.10 development.alias

从第二台机器,您应该能够使用“alias”和“development.alias”进行访问

Ok, I figured it out, here are the configuration if anyone else is looking for this:

==================================================================================

Machine A (Apache HTTP Server):
httpd-vhost:

NameVirtualHost *:50080

<VirtualHost *:50080>
    DocumentRoot "C:/www/HTTP"
    ServerName localhost
    ServerAlias alias <!-- Added -->
</VirtualHost>

<VirtualHost *:50080>
    ServerAdmin [email protected]
    DocumentRoot "C:/www/HTTP/development"
    ServerName development.localhost
    ServerAlias development.phoenix <!-- Added -->
    ErrorLog "logs/development.localhost-error.log"
    CustomLog "logs/development.localhost-access.log" common
</VirtualHost>

hosts:

127.0.0.1 development.localhost

127.0.0.1 alias
127.0.0.1 development.alias

==================================================================================

Machine B (Guest Machine):
hosts:

10.0.0.10 alias
10.0.0.10 development.alias

From the second machine, you should be able to access with "alias" and "development.alias"

梦幻的味道 2024-12-07 17:08:15

我建议进行以下更改(添加 ServerAlias 行):

NameVirtualHost *:50080
<VirtualHost *:50080>
    DocumentRoot "C:/www/HTTP"
    ServerName localhost
    ServerAlias cms.myserver.com
</VirtualHost>

<VirtualHost *:50080>
    ServerAdmin [email protected]
    DocumentRoot "C:/www/HTTP/development"
    ServerName development.localhost 
    ServerAlias development.myserver.com
    ErrorLog "logs/development.localhost-error.log"
    CustomLog "logs/development.localhost-access.log" common
</VirtualHost>

重新启动 Apache 以确保更改生效。

然后,在您的第二台计算机上,您需要为这些新域名添加自定义 dns 条目。如果是Windows,则编辑文件c:\windows\system32\drivers\etc\hosts。如果是Linux,则编辑/etc/hosts。无论哪种方式添加:

10.0.0.10 development.myserver.com
10.0.0.10 cms.myserver.com

现在在您的第二台计算机上您应该能够访问以下 URL:

http://development.myserver.com:50080
http://cms.myserver.com:50080

I suggest making the following change (add the ServerAlias lines):

NameVirtualHost *:50080
<VirtualHost *:50080>
    DocumentRoot "C:/www/HTTP"
    ServerName localhost
    ServerAlias cms.myserver.com
</VirtualHost>

<VirtualHost *:50080>
    ServerAdmin [email protected]
    DocumentRoot "C:/www/HTTP/development"
    ServerName development.localhost 
    ServerAlias development.myserver.com
    ErrorLog "logs/development.localhost-error.log"
    CustomLog "logs/development.localhost-access.log" common
</VirtualHost>

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:

10.0.0.10 development.myserver.com
10.0.0.10 cms.myserver.com

Now on your second computer you should be able to access the following URLs:

http://development.myserver.com:50080
http://cms.myserver.com:50080
飘过的浮云 2024-12-07 17:08:15

除非我遗漏了什么,否则您需要设置 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.

多彩岁月 2024-12-07 17:08:15

使用 SSH + Putty 隧道,因此我的服务器上有 127.0.0.1,我通过在服务器端执行以下操作来设法访问我的子域:

# nano /etc/hosts

127.0.0.1  localhost.localdomain localhost
127.0.0.1  sub1.domain.com sub2.domain.com sub3.domain.com sub4.domain.com

我没有更改远程计算机的主机文件,它的工作方式就像魅力

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:

# nano /etc/hosts

127.0.0.1  localhost.localdomain localhost
127.0.0.1  sub1.domain.com sub2.domain.com sub3.domain.com sub4.domain.com

I did not change the host file of the remote computer, and it works like a charm

别靠近我心 2024-12-07 17:08:15

对于命名虚拟主机,您需要使用主机名或域名来连接到您的 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.

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