我的Apache配置存在问题。我只使用一个Apache实例来提供多个网站和php应用程序 一个php应用程序安装了SSL证书:我在我的虚拟主机中使用此代码,以便重定向https上的所有http请求:
<VirtualHost *:80>
ServerName app.domain1.com
Redirect permanent / https://app.domain1.com/
</VirtualHost>
SSLStrictSNIVHostCheck on
<VirtualHost *:443>
ServerName app.domain1.com
DocumentRoot [...]
<Directory [...]>
Options FollowSymLinks MultiViews
AllowOverride All
Order deny,allow
Allow from all
</Directory>
# ssl certificate
SSLEngine on
SSLProtocol all
SSLCertificateFile [path to .crt file]
SSLCertificateKeyFile [path to .key file]
SSLCACertificateFile [path to .crt file]
# x-frame-option
Header always append X-Frame-Options SAMEORIGIN
# sts
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</VirtualHost>
此配置有效:如果我转到app.domain1.com,Apache会在https://app.domain1.com上重定向此请求,并且证书可以正常工作。
我在没有SSL的同一Apache服务器上为其他网站配置了其他虚拟主机(例如www.domain2.com)。如果我转到https://www.domain2.com我收到安全消息,因为证书(!!!)与domain2.com无关,但与domain1.com有关。
如何拒绝非https域的所有https请求?
这是我的domain2虚拟主机配置:
<VirtualHost *:80>
ServerName www.domain2.com
DocumentRoot [...]
<Directory [...]>
Options FollowSymLinks MultiViews
AllowOverride FileInfo
Order deny,allow
Allow from all
</Directory>
</VirtualHost>