我的网站(假设 abc.com)在 http 上运行,在 https 上运行不畅。在 httpd.conf 中添加以下几行后,
ServerName abc.com
DocumentRoot "c:/wamp/www/"
Listen 443
SSLEngine on
SSLCertificateFile C:/MyPath/MyCertcer
SSLCertificateKeyFile C:/MyPath/MyKey.key
SSLCACertificateFile C:/MyPath/MyCAA.crt
我的网站在 https 上开始工作,但在 http 上停止工作。这些设置不在虚拟主机或目录中。我得到,
Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
Apache/2.4.9 (Win64) OpenSSL/1.0.1g PHP/5.5.12 Server at abc.com Port 443
在我的顶部我也有,
Listen 0.0.0.0:80
Listen [::0]:80
答案1
多个 httpd.conf 配置即可。例如:
Listen 80
Listen 443
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
ServerName abc.com
DocumentRoot "c:/wamp/www/"
</VirtualHost>
<VirtualHost *:443>
ServerName abc.com
DocumentRoot "c:/wamp/www/"
SSLEngine on
SSLCertificateFile C:/MyPath/MyCert.cer
SSLCertificateKeyFile C:/MyPath/MyKey.key
</VirtualHost>
答案2
当您已经拥有证书并且 SSL 正在运行时,您可以将所有请求重定向到安全的 SSL 站点:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot c:/wamp/www/
SSLEngine on
SSLCertificateFile C:/MyPath/MyCertcer
SSLCertificateKeyFile C:/MyPath/MyKey.key
SSLCACertificateFile C:/MyPath/MyCAA.crt
</VirtualHost>