Apache 适用于 IP,但不适用于域名

Apache 适用于 IP,但不适用于域名

我已经通过在 apache 虚拟主机设置中使用我的 Web 可访问 IP 地址 (xx.xx.xx.xx) 非常顺利地运行了 apache 服务器一段时间,如下所示:

<VirtualHost *:80>
 DocumentRoot "/var/www/app"
 ServerName xx.xx.xx.xx
 <Directory /var/www/app>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
 </Directory>

 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我对这个配置没有遇到任何问题。然后我购买了一个域名,比如 foo.com,但尝试使用 Apache 设置它时却没有成功——无论虚拟主机配置如何。当我将之前的配置替换为

<VirtualHost *:80>
 DocumentRoot "/var/www/app"
 ServerName foo.com
 AliasName *.foo.com
 <Directory /var/www/app>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
 </Directory>

 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

然后我被转到经典的 Apache2 Ubuntu 默认页面。我尝试了其他配置,例如

<VirtualHost xx:xx:xx:xx:80>
 DocumentRoot "/var/www/app"
 ServerName foo.com
 <Directory /var/www/app>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
 </Directory>

 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

结果相同。我尝试了许多其他配置,例如同时为 IP 和域设置一个配置(这样 IP 地址就可以正常工作,但当我输入 foo.com 时,会显示“:( xx.xx.xx.xx 连接被拒绝”)。我还尝试过使用 AliasName,但无济于事。

我是否遗漏了可以解决此问题的故障排除任务,或者是否有明显的答案?我在我的 DNS 服务 (bluehost) 上配置了 A 和 AAAA 记录。似乎名称已映射到正确的 IP,并且当连接到达我的服务器时会发生问题。虽然到达配置页面很好,但我希望 Web 应用程序能够运行。

谢谢

编辑:

我也一直在使用

Listen 80
NameVirtualHost *:80

.conf 文件中的指令。

以下是“apachectl -S”的输出

AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/config.conf:3
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server 127.0.0.1 (/etc/apache2/sites-enabled/000-default.conf:2)
         port 80 namevhost 127.0.0.1 (/etc/apache2/sites-enabled/000-default.conf:2)
         port 80 namevhost foo.com (/etc/apache2/sites-enabled/config.conf:6)
                 wild alias *.foo.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

以下是 access.log 的输出

yy.yy.yy.yy - - [01/Oct/2020:14:54:32 -0400] "GET / HTTP/1.1" 302 1237 "http://foo. com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
yy.yy.yy.yy - - [01/Oct/2020:14:54:33 -0400] "GET /index.php/dashboard HTTP/1.1" 302 442 "http://foo. com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
yy.yy.yy.yy - - [01/Oct/2020:14:54:33 -0400] "GET /index.php/user/auth/login HTTP/1.1" 200 9140 "http://foo. com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
                       

以下是 xx.xx.xx.xx 的访问日志中的前两行

yy.yy.yy.yy - - [01/Oct/2020:15:18:34 -0400] "GET /index.php/dashboard HTTP/1.1" 200 18928 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
yy.yy.yy.yy - - [01/Oct/2020:15:18:36 -0400] "GET /assets/eead54sf/js/test.js?v=28611 HTTP/1.1" 200 1063 "http://xx.xx.xx.xx/index.php/dashboard" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"

相关内容