我在debian上安装了certbot来安装,以便将证书加密到apache2。
一切都像魅力一样,我选择了软件选项,将http流量重定向到https。
该软件以这种方式更改了我的apache2 conf文件:
<VirtualHost *:80>
ServerName myweburl.com
ServerAlias www.myweburl.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myweburl/public
<Directory /var/www/html/myweburl>
Options FollowSymLinks MultiViews
Order Allow,Deny
Allow from all
AllowOverride All
ReWriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
/////////
// The software added these lines
/////////
RewriteCond %{SERVER_NAME} =myweburl.com [OR]
RewriteCond %{SERVER_NAME} =www.myweburl.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
这些行不起作用。
如果我访问myweburl.com,它不会重定向。
如果我访问https:// www.myweburl.com,则可以看到正确的已安装证书。
对于当前版本的Apache,可能有几种方法可以解决此问题:
%{HTTP_HOST}
而不是%{SERVER_NAME}
前任。使用%HTTP_HOST
<VirtualHost *:80>
ServerName myweburl.com
ServerAlias www.myweburl.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myweburl/public
<Directory /var/www/html/myweburl>
Options FollowSymLinks MultiViews
Order Allow,Deny
Allow from all
AllowOverride All
RewriteEngine on
RewriteCond %{HTTP_HOST} myweburl.com [OR]
RewriteCond %{HTTP_HOST} www.myweburl.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [END,NE,R=permanent]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Redirect
。这要求启用mod_alias。前任。使用Redirect
<VirtualHost *:80>
ServerName myweburl.com
ServerAlias www.myweburl.com
ServerAdmin webmaster@localhost
# DocumentRoot /var/www/html/myweburl/public
Redirect permanent / https://myweburl.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Rewrite
规则。您可以在此处阅读有关mod_rewrite重新映射的更多信息。前任。替代mod_rewrite
规则
<VirtualHost *:80>
ServerName myweburl.com
ServerAlias www.myweburl.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myweburl/public
<Directory /var/www/html/myweburl>
Options FollowSymLinks MultiViews
Order Allow,Deny
Allow from all
AllowOverride All
RewriteEngine on
RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=permanent]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句