Apache上的一个虚拟主机在WAN上不可见,仅在LAN上可见

我无法在Windows 7上的Apache 2.4.12 32位上设置虚拟主机。我可以在以前的版本中执行此操作,但是现在即使按照官方说明,我也无法正确设置虚拟主机。 我试图设置2个虚拟主机,一个用于端口8080 ,另一个用于端口8081 。 我没有一个“主”服务器,只有2个虚拟主机设置。 本地,一切工作正常。 我可以在127.0.0.1:8080127.0.0.1/8081访问它们,但是当我使用my Public IP:8080my 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 

我究竟做错了什么?

更改你的configuration,让vhost2侦听端口8080,而vhost1监听8081.如果vhost2现在可以使用public_ip:8080访问,可以推定服务器configuration正常,可能是你的networkingconfiguration问题。

HTH。