我已经使用 certbot 为网站生成了 https 证书,但没有预先生成从 http 到 https 自动重定向的配置。现在我尝试手动配置它,但使用以下配置:
<VirtualHost 127.0.0.1:8080>
ServerName website.com
ServerAlias www.website.com
DocumentRoot /var/www/www-root/data/www/website.com
ServerAdmin [email protected]
DirectoryIndex index.php index.html
AddDefaultCharset off
SuexecUserGroup www-root www-root
CustomLog /var/www/httpd-logs/website.com.access.log combined
ErrorLog /var/www/httpd-logs/website.com.error.log
<FilesMatch "\.ph(p[3-5]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
<IfModule php5_module>
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f [email protected]"
php_admin_value upload_tmp_dir "/var/www/www-root/data/mod-tmp"
php_admin_value session.save_path "/var/www/www-root/data/mod-tmp"
php_admin_value open_basedir "/var/www/www-root/data:."
</IfModule>
<IfModule php7_module>
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f [email protected]"
php_admin_value upload_tmp_dir "/var/www/www-root/data/mod-tmp"
php_admin_value session.save_path "/var/www/www-root/data/mod-tmp"
php_admin_value open_basedir "/var/www/www-root/data:."
</IfModule>
SetEnvIf X-Forwarded-Proto https HTTPS=on
RewriteEngine on
RewriteCond %{SERVER_NAME} =website.com [OR]
RewriteCond %{SERVER_NAME} =www.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,QSA,R=permanent]
</VirtualHost>
<Directory /var/www/www-root/data/www/website.com>
Options +Includes -ExecCGI
<IfModule php5_module>
php_admin_flag engine on
</IfModule>
<IfModule php7_module>
php_admin_flag engine on
</IfModule>
</Directory>
我在浏览器中收到 TOO_MANY_REDIRECTS 错误。
Redirect / https://website.com
规则。为什么会发生这种情况以及如何解决?