如何解决Certbot 无法为子域正常工作
我有一个带有 SSL Certbot 的 VPS 服务器,在带有 apache 的 Debian 中,但对于子域无法正常工作。当使用 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 升级和配置文件更改时,这会少很多麻烦,因为在更改默认文件时,您会看到一个对话框,并且必须决定要保留哪个版本。选择错误,您必须从备份中恢复更改的配置文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。