使用 Apache2 重定向的 LetsEncrypt
LetsEncrypt with Apache2 Redirection
我正在努力处理我的域的 https 重定向。我的域由 godaddy 托管,我的服务器由 ionos 托管。我能够安装 ssl 认证,如果我直接访问 https://domain.com,它会按预期工作。不幸的是,重定向根本不起作用。
conf 文件如下所示:
<VirtualHost *:80>
ServerAdmin admin@domain.de
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.com [OR]
RewriteCond %{SERVER_NAME} =www.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
和这样的 ssl conf 文件:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@domain.de
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
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} =domain.com [OR]
# RewriteCond %{SERVER_NAME} =www.domain.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
</VirtualHost>
</IfModule>
我希望有人对此有想法。
非常感谢!
这应该可以,将它放在虚拟主机之外(可能不会有什么不同),并确保 mod_rewrite 已打开。
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
编辑:
为重定向添加了标志 R=301 和 L。
信息:
如果将上面的内容放在虚拟主机之外时不起作用,则应在 RewriteEngine On
:
之后添加以下内容
RewriteOptions InheritDown
我正在努力处理我的域的 https 重定向。我的域由 godaddy 托管,我的服务器由 ionos 托管。我能够安装 ssl 认证,如果我直接访问 https://domain.com,它会按预期工作。不幸的是,重定向根本不起作用。
conf 文件如下所示:
<VirtualHost *:80>
ServerAdmin admin@domain.de
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.com [OR]
RewriteCond %{SERVER_NAME} =www.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
和这样的 ssl conf 文件:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@domain.de
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
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} =domain.com [OR]
# RewriteCond %{SERVER_NAME} =www.domain.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
</VirtualHost>
</IfModule>
我希望有人对此有想法。
非常感谢!
这应该可以,将它放在虚拟主机之外(可能不会有什么不同),并确保 mod_rewrite 已打开。
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
编辑:
为重定向添加了标志 R=301 和 L。
信息:
如果将上面的内容放在虚拟主机之外时不起作用,则应在 RewriteEngine On
:
RewriteOptions InheritDown