Certbot 无法为子域正常工作

Certbot not working correctly for subdomain

我有一个带 SSL Certbot 的 VPS 服务器,在 Debian 中,带 apache,但对于子域无法正常工作。当使用 http:// 访问我的子域时,它直接进入我配置的目录。

但是,使用https://协议访问时,直接进入根目录,即/var/www/html.

我是 VPS 服务器的新手,我不知道问题是什么。

这是我的/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =app.mysite.com [OR]
        RewriteCond %{SERVER_NAME} =mysite.com [OR]
        RewriteCond %{SERVER_NAME} =www.mysite.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

<VirtualHost *:80>
   ServerName app.mysite.com
   DocumentRoot /var/www/html/app
</VirtualHost>

感谢您的宝贵时间

您的配置示例缺少 https/端口 443 的配置。

来自您的 http 配置

<VirtualHost *:80>
   ServerName app.mysite.com
   DocumentRoot /var/www/html/app
</VirtualHost>

所以您应该将 SSL 配置文件的 DocumentRoot 也更改为 DocumentRoot /var/www/html/app。可能这个文件叫做 000-default-ssl.conf.

通常创建自己的文件并使用它们而不是默认文件是个好主意。尤其是当你进行 dist 升级和配置文件更改时,这就更容易了,因为在更改默认文件时,你会看到一个对话框,必须决定要保留哪个版本。选择错误,您必须从备份中恢复更改的配置文件。