【问题标题】:Certbot not working correctly for subdomainCertbot 无法在子域中正常工作
【发布时间】:2021-07-30 05:05:25
【问题描述】:

我有一个带有 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 配置文件。

标签: apache2 certbot debian-buster


【解决方案1】:

您的配置示例缺少 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 升级和配置文件更改时,这会少很多麻烦,因为在更改默认文件时,您会看到一个对话框,并且必须决定要保留哪个版本。选择错误,您必须从备份中恢复更改的配置文件。

【讨论】:

  • 是的!我解决了我的问题,我在000-default-ssl.conf 文件中将端口 80 更改为 443。非常感谢朋友
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-05
  • 2013-10-07
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多