我的配置是:
Listen 443 http
NameVirtualHost *:80
NameVirtualHost *:443
ServerName *:80
<VirtualHost *:80>
[some non-ssl stuff]
ServerName account.example.com
</VirtualHost>
<VirtualHost *:443>
[some non-ssl stuff(directory, docroot)]
ServerName account.example.com
SSLEngine on
SSLCertificateFile /Users/myusername/certs/server.crt
SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>
所以我无法访问我网站的http版本,但ssl版本正常运行。我想使用vhosts,http(80)和https(443)通过mod_rewrite将http重写为https URL。
uname -a
Linux 3.4.62-53.42.amzn1.x86_64 GNU/Linux
httpd -v
Server version: Apache/2.2.25 (Unix)
请帮助理解我做错了什么。
答案 0 :(得分:10)
所以,我的配置现在是:
Listen 443 http
Listen 80
NameVirtualHost *:80
NameVirtualHost *:443
ServerName *:80
<VirtualHost *:443>
[some non-ssl stuff(directory, docroot)]
ServerName account.example.com
SSLEngine on
SSLCertificateFile /Users/myusername/certs/server.crt
SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>
<VirtualHost *:80>
SSLEngine off
[other stuff like docroot]
</VirtualHost>
不确定SSLEngine off
,但现在可行了。所以,我在http vhost&#39; s .htaccess文件中添加重写规则从http到https重新修改:
#Redirrect from http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]