如何在 Apache 2.2 上设置虚拟主机

发布于 2024-07-19 08:24:16 字数 389 浏览 8 评论 0原文

任何人都可以指导我有关如何使用 Apache 2.2 设置虚拟主机的好教程吗? 我的情况是这样的:

我的笔记本电脑上运行着 Apache,我想要两个网站 - 一个在端口 80 上,一个在端口 8089 上。我想通过输入计算机的 IP 地址从网络上的另一台计算机访问每个站点,例如http://192.168.1.102http://192.168.1.102:8089。 然而,当我输入第二个网址时,它会将我定向到在端口 80 上运行的网站。

提前感谢您的帮助。

Can anyone direct me to a good tutorial on how to set up virtual hosts using Apache 2.2? Here's my situation:

I have Apache running on my laptop and I want two websites-- one on port 80 and one on port 8089. I want to access each site from the other computer on my network by entering the computer's IP address, such as http://192.168.1.102 and http://192.168.1.102:8089. Yet when I enter the second url, it directs me to the website running on port 80.

Thanks in advance for any help.

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

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

发布评论

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

评论(2

早茶月光 2024-07-26 08:24:16

首先,您需要指示 Apache 监听您需要的端口:

Listen 80
Listen 8089

其次,您需要告诉它如何处理 80 和 8089 流量:

<VirtualHost *:80>
    DocumentRoot /website/site80
    ServerName internet.dev
</VirtualHost>

<VirtualHost *:8089>
    DocumentRoot /website/site8089
</VirtualHost>

第三,您需要“允许”Apache 使用这些目录:

<Directory "C:/website/site80">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "C:/website/site8089">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

First you need to instruct Apache to listen on the ports you need:

Listen 80
Listen 8089

Second you need to tell it what to do with 80 and 8089 traffic:

<VirtualHost *:80>
    DocumentRoot /website/site80
    ServerName internet.dev
</VirtualHost>

<VirtualHost *:8089>
    DocumentRoot /website/site8089
</VirtualHost>

Third you need to "allow" Apache to use those directories:

<Directory "C:/website/site80">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "C:/website/site8089">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
携君以终年 2024-07-26 08:24:16

只需像这样定义 2 个虚拟主机,但具有不同的 DocumentRoots:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>

<VirtualHost *:8089>
    ServerAdmin [email protected]
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>

Just have 2 virtual hosts defined like this, but with differeing DocumentRoots:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>

<VirtualHost *:8089>
    ServerAdmin [email protected]
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文