我从Let's Encrypt获得了SSL证书,在安装过程中使用错误的选择搞乱了安装后,我相信我在000-default.conf
文件中有一些损坏的代码,因为目前只有我键入{{1它将我重定向到example.com
,但是当我输入https://example.com/
时,它会在没有HTTPS的情况下离开www.example.com
。这就是www.example.com
目前的样子:
000-default.conf
编辑:让加密在网站内创建更多文件 - 与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} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
:
000-default-le-ssl.conf
我有www.example.com和example.com的证书。 我需要编辑哪些内容才能阻止www.example.com访问常规HTTP并将其重定向到HTTPS?我找不到
由于
答案 0 :(得分:0)
您需要将服务器名称和别名包含在虚拟主机
中<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName website.com
ServerAlias www.website.com
RewriteEngine On
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
这会强制重定向两个网址。请注意,您的规则过去仅限于非www网址。
答案 1 :(得分:0)
你可以告诉它将端口80重定向到端口443,这就是我猜你正在运行你的ssl的地方,这是一个例子: