Apache 提供子域名服务,而不是域名服务

Apache 提供子域名服务,而不是域名服务

我的服务器上有两个站点正在运行(nextcloud.example.comNextcloud 实例和example.comGrav 实例)。我在服务器上添加了 Postfix 配置,现在我也可以发送邮件了。但我弄乱了我的证书,所以我重做了它们……

主要问题现在是,当我尝试打开时,example.com它总是调用example.com/index.php/login,从中呈现登录页面,nextcloud.example.com但我期待我的 Grav 主页。此外,当我调用它时,example.com/admin它会解析为example.com/index.php/login

我对这个主题还很陌生,所以我希望这是相关的数据:

$ apachectl configtest
Syntax OK

我确实在这里插入了我的配置文件,但 StackExchange 将我的文本区域标记为垃圾邮件。所以我删除了它们。我很高兴为您提供更多信息,只是我不被允许……

编辑:

apache2ctl -S
VirtualHost configuration:
127.0.1.1:443          example.com (/etc/apache2/sites-enabled/example.com-le-ssl.conf:2)
127.0.1.1:80           example.com (/etc/apache2/sites-enabled/example.com.conf:1)
5.252.225.176:443      nextcloud.example.com (/etc/apache2/sites-enabled/nextcloud.example.com-le-ssl.conf:2)
5.252.225.176:80       nextcloud.example.com (/etc/apache2/sites-enabled/nextcloud.example.com.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
<VirtualHost nextcloud.example.com:443>
  DocumentRoot /var/www/nextcloud.example.com/htdocs/
  ServerName  nextcloud.example.com

  <Directory /var/www/nextcloud.example.com/htdocs/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
RewriteEngine off
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

#RewriteCond %{SERVER_NAME} =nextcloud.example.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost example.com:443>
  DocumentRoot /var/www/example.com/htdocs/
  ServerName  example.com

  <Directory /var/www/example.com/htdocs/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

#RewriteCond %{SERVER_NAME} =example.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

答案1

您可能需要将 VirtualHost 指令中的主机名更改为*。也就是说,而不是

<VirtualHost nextcloud.example.com:443>
  ServerName  nextcloud.example.com
  ...
</VirtualHost>
<Virtualhost example.com:443>
  ServerName  example.com
  ...
</VirtualHost>

尝试

<VirtualHost *:443>
  ServerName  nextcloud.example.com
  ...
</VirtualHost>
<Virtualhost *:443>
  ServerName  example.com
  ...
</VirtualHost>

VirtualHost的参数一般应该是一个IP地址,或者*匹配所有的IP地址。

如果 Apache 接收连接的 IP 地址与 example.com 的 DNS 地址不同(例如,如果 example.com 位于代理后面),则上述第一种形式将失败。在这种情况下,Apache 将回退到从默认虚拟主机提供服务,即第一个虚拟主机,在您的情况下似乎是 nextcloud.example.com。

虚拟主机, 和基于名称的虚拟主机

相关内容