使用虚拟主机在Apache中配置Ssl
我想为Ssl连接配置apache,但是当我尝试访问使用https的网站是不可能的。使用虚拟主机在Apache中配置Ssl
这里是虚拟主机为我的网站:
<VirtualHost *:443>
DocumentRoot "C:\xampp\htdocs\www.example.com"
ServerName www.example.com
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:\xampp\htdocs\www.example.com"
ServerName example.com
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
</VirtualHost>
我已经这条线在C之前忽略#:\ XAMPP \ apache的\的conf \ httpd.conf中 LoadModule rewrite_module modules/mod_rewrite.so
我有添加此行在C:\ XAMPP的\ apache的\的conf \额外\的httpd-xampp.con
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect /xampp folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} xampp
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /phpMyAdmin folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} phpmyadmin
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /security folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} security
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /webalizer folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} webalizer
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</IfModule>
我增加了一个SSLRequireSSL指令下列文件中的每个目录内:
Config File: c:\xampp\apache\conf\extra\httpd-xampp.conf
c:\xampp\phpmyadmin
c:\xampp\htdocs\xampp
c:\xampp\webalizer
c:\xampp\security\htdocs
Config File: c:\xampp\webdav
c:\xampp\webdav
错误日志,当我重新启动Apache:
[Fri Jun 23 10:00:24.739140 2017] [ssl:warn] [pid 5012:tid 268] AH01909: RSA certificate configured for localhost:443 does NOT include an ID which matches the server name
[Fri Jun 23 10:00:24.742070 2017] [ssl:warn] [pid 5012:tid 268] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Fri Jun 23 10:00:24.947148 2017] [ssl:warn] [pid 5012:tid 268] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Jun 23 10:00:24.948125 2017] [ssl:warn] [pid 5012:tid 268] AH01909: RSA certificate configured for localhost:443 does NOT include an ID which matches the server name
[Fri Jun 23 10:00:24.949101 2017] [ssl:warn] [pid 5012:tid 268] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Fri Jun 23 10:00:25.077031 2017] [mpm_winnt:notice] [pid 5012:tid 268] AH00354: Child: Starting 150 worker threads.
谁能告诉我我在做什么错误或丢失?
请问您可以更改服务器名称指令来匹配证书通用名称作为Apache日志建议? 要验证您的证书中使用的通用名称匹配您的服务器名称,请运行
openssl x509 -in server.crt -noout -subject
如果这不起作用,你可以请使用完全合格的域名,如mydomain.dev。要使其工作,请在您的主机文件中添加域以使用环回IP 127.0.0.1解析 - 这与我的文章中的步骤1类似https://www.bizmate.biz/articles-mainmenu-2/18-little-it-tricks/48-ssl-virtualhost-apache2-xampp
这是如何更改您的hosts文件。 https://support.rackspace.com/how-to/modify-your-hosts-file/
同样为了确定SSL配置是否正确,您可以关注一下并关闭mod_rewrite一会儿。事实上,如果它不起作用,请使用我文章中的步骤来回复信件,并恢复到目前为止所做的任何更改/从头开始。然后,一旦你的浏览器和Apache对证书和SSL加密感到满意,你就可以在以后使用mod_rewrite。
我用127.0.0.1代替了ServerName但它不起作用。我在httpd-vhosts.conf文件中添加了127.0.0.1 www.mydomain.com行,但仍然没有任何结果。 – bsh
hosts文件与apache无关。 IT是一个强制你的机器将你的域名解析为该IP的文件。这是如何更改您的主机文件。 https://support.rackspace.com/how-to/modify-your-hosts-file/ 请将它设置为一个非常特定的域名,例如belka.dev,然后在您的apache虚拟主机中(不要与主机混淆文件)更改服务器名称。 1-禁用ssl虚拟主机并查看apache是否启动,2重新启用ssl虚拟主机并查看它是否有效,或者是否来自日志的错误。如果不这样做,请按照第3步的步骤生成ssl证书。 – Bizmate
我做了但仍然没有。错误日志说: 配置为localhost:443的RSA证书不包含与服务器名称匹配的ID [ssl:warn] [pid 5012:tid 268] AH02292:Init:基于名称的SSL虚拟主机仅适用于客户端TLS服务器名称指示支持(RFC 4366) [Fri Jun 23 10:00:24.947148 2017] [ssl:warn] [pid 5012:tid 268] AH01873:初始化:未配置会话缓存[提示: – bsh