我无法在 Windows 7 上的 Apache 2.4.12 32 位上设置虚拟主机。我可以在以前的版本中做到这一点,但现在即使按照官方说明,我也无法正确设置虚拟主机。我正在尝试设置 2 个虚拟主机,一个用于端口8080
,另一个用于端口8081
。我没有“主”服务器,只设置了 2 个虚拟主机。在本地,一切正常。我可以在和中访问它们127.0.0.1:8080
,127.0.0.1/8081
但是当我使用my Public IP:8080
和时my Public IP:8081
,只有端口 8080 上的虚拟主机在工作。端口 8081 中的那个没有被我的公共 IP 加载,尽管它正在与我的本地 IP 一起工作。这是我的 httpd-vhosts.conf:
<VirtualHost *:8080>
ServerAdmin admin@vhosts
DocumentRoot "${SRVROOT}/htdocs/vhost1"
ServerName localhost
ErrorLog "logs/vhost1-error.log"
</VirtualHost>
<Directory "${SRVROOT}/htdocs/vhost1">
Options None
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:8081>
ServerAdmin admin@vhosts
DocumentRoot "${SRVROOT}/htdocs/vhost2"
ServerName localhost
ErrorLog "logs/vhost2-error.log"
</VirtualHost>
<Directory "${SRVROOT}/htdocs/vhost2">
Options None
AllowOverride None
Require all granted
</Directory>
以下是httpd.conf的一些相关部分:
Define SRVROOT "c:/Apache24"
ServerRoot "${SRVROOT}"
Listen 8080
Listen 8081
# all default modules are loaded in this part
# 'Main' server configuration are all commented because
# I don't want a 'Main' server, only virtual hosts
#ServerAdmin admin@server
#ServerName localhost
<Directory />
Options None
AllowOverride none
Require all denied
</Directory>
DocumentRoot "${SRVROOT}/htdocs"
# Includes are as they came by default, only these are enabled:
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
# everything else as default
我究竟做错了什么?
答案1
更改您的配置并让 vhost2 监听端口 8080,而 vhost1 监听 8081。如果现在可以使用 public_ip:8080 访问 vhost2,则可以假定服务器配置没有问题,也许是您的网络配置存在问题。
嗨嗨。