Windows系统中如何配置Apache的SSL加密访问

来源:互联网 发布:只有我知3小时14分超清 编辑:程序博客网 时间:2024/06/06 01:59

到Apache的网站上下载包含有SSL服务的安装包。

如果你已经安装过了Apache,在安装含有SSL服务的Apache服务器之前需要卸载已经安装过的。到控制面板里面直接卸载就可以了。注意:Apache在卸载的时候不会删除httpd.conf这个配置文件和htdocs文件夹下面的内容。如果你确实不需要,你需要手工删除。

在Windows的环境下面安装含有SSL的Apache和不含有 Apache的方法和过程一致。

这里关键说安装以后的服务配置。
httpd.conf文件,如果需要Apache服务器支持SSL,这里需要载入几个模块。

去掉下面两行之前的#符号
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf

LoadModule ssl_module modules/mod_ssl.so的作用是载入SSL模块
apache_ssl_01.jpg  

Include conf/extra/httpd-ssl.conf的作用是告诉Apache的SSL模块到那里去找配置文件
apache_ssl_02.jpg  

重新启动服务器,测试一下看有没有什么问题。
显然在重新启动服务器的时候报了一个错误,说服务器无法正常启动。这时候我们可以看看日志文件了。
[Fri Aug 15 15:33:08 2008] [notice] Parent: Received restart signal– Restarting the server.
[Fri Aug 15 15:33:08 2008] [notice] Child 740: Exit event signaled.Child process is ending.
Syntax error on line 99 ofD:/Dkits/Apache2.2/conf/extra/httpd-ssl.conf:
SSLCertificateFile: file ‘D:/Dkits/Apache2.2/conf/server.crt’ doesnot exist or is empty
[Fri Aug 15 15:33:08 2008] [warn] (OS 995)The I/O operation hasbeen aborted because of either a thread exit or an applicationrequest.  : winnt_accept: Asynchronous AcceptExfailed.
[Fri Aug 15 15:33:09 2008] [notice] Child 740: Released the startmutex
[Fri Aug 15 15:33:10 2008] [notice] Child 740: All worker threadshave exited.
[Fri Aug 15 15:33:10 2008] [notice] Child 740: Child process isexiting

上面说在D:/Dkits/Apache2.2/conf/server.crt路径下找不到server.crt这个文件。

那么,这个文件在那里呢?
这个文件需要我们用openssl这个程序来生成的。生成这个 server.crt文件需要2个文件,一个是openssl.exe另一个是openssl.cnf。

一般来说openssl.exe在你Apache的安装路径下的bin文件夹里面,openssl.cnf在Apache安装路径下的conf文件里面。找不到?如果找不到就用windows的查找搜索一下了。这个时候你需要将openssl.exe和openssl.cnf放在同一个文件夹里面。

一般的需要将找到的openssl.cnf文件拷贝到bin文件里面。

用openssl生成KEY 生成自签名文件

首先生成csr和pem文件。
命令是:openssl req -config openssl.cnf -new -out server.csr -keyoutserver.pem
运行结果如下:
apache_ssl_03.jpg

D:DkitsApache2.2bin>openssl req -config openssl.cnf -new-out server.csr -keyout server.pem
Loading ‘screen’ into random state - done
Generating a 1024 bit RSA private key
………++++++
………++++++
writing new private key to ‘server.pem’
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
—–
You are about to be asked to enter information that will beincorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Nameor a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New Hampshire
Locality Name (eg, city) []:Manchester
Organization Name (eg, company) [Internet Widgits PtyLtd]:CUIST
Organizational Unit Name (eg, section) []:IT Section
Common Name (eg, YOUR name) []:localhost
Email Address []:huyuchengus@gmail.com

Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

D:DkitsApache2.2bin>

其中有几个地方需要注意
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
用于输入和重复输入密码的,密码长度不能小于4位

Common Name (eg, YOUR name) []:localhost
用于输入客户端能够访问SSL的地址:这里SSL服务器是在本地运行的,因此你可以输入localhost如果你的SSL地址运行网站主机上,那么这里需要输入例如www.cuist.com了。

An optional company name []:留空,如果输入将会报错。
apache_ssl_04.jpg

其他的提示输入部分,可以输入也可以留空,最重要的就是Common Name (eg, YOUR name)[]:这个变量,关系到你的SSL服务能不能够运行。

为Apache创建没有密码保护的key 下面需要为Apache创建一个没有密码保护的key了。

命令是openssl rsa -in server.pem -out server.key

运行结果如下
apache_ssl_05.jpg  

在这里你需要输入密码,这个密码是你在上一步输入过的。如果没有错误,你将会看到writing RSAkey这句话后面没有任何内容和错误提示。

创建X.509证书 现在需要为Apache创建X.509证书了。
命令是:openssl x509 -in server.csr -out server.crt -req -signkeyserver.key -days 365

结果如下:
apache_ssl_06.jpg

如果没有错误,将会看到签名已经成功,后面有签名的详细信息和内容。

现在你再看看opensel.exe所在的文件夹下面是不是多了4个文件了,分别是:server.pem,server.key,server.csr,server.crt
apache_ssl_07.jpg  

其实我们并不需要所有的这4个文件,我一向喜欢偷懒,就把这4个文件直接拷贝到conf文件夹下面保存。

重新启动错误 如果重新启动没有错误,但是还是不能访问。

这时候你需要检查日志文件,有一种可能是443端口的冲突,如果你的机器已经安装了IIS,那需要将IIS的web服务,FTP,SMTP服务全部关掉再重新启动。

如果既没有日志输出,也不能访问,那是因为配置文件没有被正确的载入,这时候你需要先在httpd.conf文件里面注释掉这句话Includeconf/extra/httpd-ssl.conf,然后重新启动Apache的服务。等服务成功启动以后,再打开这句话,再重新启动服务。这时候你就能看到日志的输出了。否则不管你重新启动多少次,Apache还是只会载入老的httpd-ssl.conf文件,不会重新读取httpd-ssl.conf的。

如果在日志里面有警告
[Fri Aug 15 16:15:10 2008] [warn] RSA server certificate CommonName(CN) `localhost’ does NOT match server name!?
[Fri Aug 15 16:15:10 2008] [notice] Child 3664: Released the startmutex
[Fri Aug 15 16:15:10 2008] [warn] RSA server certificate CommonName(CN) `localhost’ does NOT match server name!?
那是因为你输入的SSL服务为localhost但是你Apache在安装的时候服务却不是localhost。这时候你需要改几个地方。

httpd-ssl.conf文件中的
apache_ssl_08.jpg  

# ServerAdmin: Your address, where problems with the servershould be

# e-mailed.  This address appears on someserver-generated pages, such
# as errordocuments.  e.g. admin@your-domain.com
#
ServerAdmin admin@rochester.cuist.local

将ServerAdmin 变量中admin@rochester.cuist.local的改成admin@localhost

保存上述两个配置文件后重新启动Apache服务器,如果没有日志输出,则需要先在httpd.conf文件里面注释掉这句话Includeconf/extra/httpd-ssl.conf,然后重新启动Apache的服务。等服务成功启动以后,再打开这句话,再重新启动服务。

在输出的日志里面应该不会包含有任何的警告信息了。
[Fri Aug 15 16:29:13 2008] [notice] Parent: Received restart signal– Restarting the server.
[Fri Aug 15 16:29:13 2008] [notice] Child 3908: Exit eventsignaled. Child process is ending.
[Fri Aug 15 16:29:13 2008] [notice] Apache/2.2.9 (Win32)mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6 configured – resumingnormal operations
[Fri Aug 15 16:29:13 2008] [notice] Server built: Jun 13 200804:04:59
[Fri Aug 15 16:29:13 2008] [notice] Parent: Created child process2976
[Fri Aug 15 16:29:14 2008] [notice] Child 3908: Released the startmutex
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Child process isrunning
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Acquired the startmutex.
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Starting 64 workerthreads.
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Starting thread tolisten on port 443.
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Starting thread tolisten on port 80.
[Fri Aug 15 16:29:15 2008] [notice] Child 3908: All worker threadshave exited.
[Fri Aug 15 16:29:15 2008] [notice] Child 3908: Child process isexiting
apache_ssl_10.jpg

#   General setup for the virtual host
DocumentRoot “D:/Dkits/Apache2.2/htdocs”
ServerName CUIST_PC02.rochester.cuist.local:443
ServerAdmin admin@rochester.cuist.local
ErrorLog “D:/Dkits/Apache2.2/logs/error.log”
TransferLog “D:/Dkits/Apache2.2/logs/access.log”

将ServerName CUIST_PC02.rochester.cuist.local:443变量中的CUIST_PC02.rochester.cuist.local:443改成localhost:443
将ServerAdmin 变量中admin@rochester.cuist.local的 改成admin@localhost

httpd.conf文件中的
apache_ssl_09.jpg  

HTTP服务启动在80端口,SSL服务启动在443端口。

验证 在HTTP能正常访问的地址下面加上S变成https。

如果http://localhost/phpMyAdmin/index.php变化成https://localhost/phpMyAdmin/index.php

这时候应该能够看到一个证书警告的信息
apache_ssl_11.jpg


同意这个证书,看看是不是能够看到web页面了呀,如果能,则说明SSL已经被正确的配置到Apache服务里面来了。可以轻松一下了喔。。




转载请注明原文地址:http://www.server110.com/apache/201404/9462.html

SyntaxHighlighter.all();
          <div class="FR">            <script src="/money_js/article_content_below_2.js"></script><script type="text/javascript">var cpro_id = "u1489212";</script><script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script><div id="BAIDU_SSP__wrapper_u1489212_0"><iframe id="iframeu1489212_0" src="http://pos.baidu.com/nchm?rdid=1489212&amp;dc=2&amp;di=u1489212&amp;dri=0&amp;dis=0&amp;dai=4&amp;ps=7846x1092&amp;dcb=BAIDU_SSP_define&amp;dtm=BAIDU_DUP_SETJSONADSLOT&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1466148503840&amp;ti=Windows%E7%B3%BB%E7%BB%9F%E4%B8%AD%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AEApache%E7%9A%84SSL%E5%8A%A0%E5%AF%86%E8%AE%BF%E9%97%AE%20-%20Apache%20-%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B9%8B%E5%AE%B6&amp;ari=1&amp;dbv=0&amp;drs=1&amp;pcs=1903x922&amp;pss=1903x8098&amp;cfv=21&amp;cpl=22&amp;chi=1&amp;cce=true&amp;cec=gbk&amp;tlm=1461821975&amp;ltu=http%3A%2F%2Fwww.server110.com%2Fapache%2F201404%2F9462.html&amp;ltr=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DlPWw97vbOeBwu9z_yJfFtxI8ayRm8e6XaM8MBlO0H0REU-9mtB2sYL5lyW-eN5I-Q3hZWbcrXpdWIfpeychWE_%26wd%3D%26eqid%3Db417a1b5000091ba000000035763a5b6&amp;ecd=1&amp;psr=1920x1080&amp;par=1920x1040&amp;pis=-1x-1&amp;ccd=24&amp;cja=true&amp;cmi=66&amp;col=zh-CN&amp;cdo=-1&amp;tcn=1466148504&amp;qn=d2f97eac01495c26&amp;tt=1466148503815.574.736.736" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" style="border:0; vertical-align:bottom;margin:0;" allowtransparency="true" align="center,center" frameborder="0" height="250" width="300"></iframe></div>          </div>        </div>        <div class="clear"></div>          <div class="listpages"></div>        <script src="/money_js/article_subpagelist_below.js"></script><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins data-adsbygoogle-status="done" class="adsbygoogle" style="display:inline-block;width:468px;height:60px" data-ad-client="ca-pub-1892357599595152" data-ad-slot="2197532646"><ins id="aswift_3_expand" style="display:inline-table;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px;background-color:transparent"><ins id="aswift_3_anchor" style="display:block;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px;background-color:transparent"><iframe marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_3" name="aswift_3" style="left:0;position:absolute;top:0;" frameborder="0" height="60" width="468"></iframe></ins></ins></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>    </div>
0 0
原创粉丝点击