Apache+OPENSSL+Tomcat配置

   首先下载httpd-2.0.65-win32-x86-openssl-0.9.8y.msi

SSL是一个可以保证你的通讯安全的机制,采用非对加密机制。

此篇文章使用openssl建立自己的密钥,并部署在Apache Webserver上,让服务器支持https

首先进入到openssl.exe所在目录,设置openssl.cnf的位置,在cmd命令窗口输入set openssl_conf=../conf/openssl.cnf

      1、 产生server.key

F:\Apache2.2\bin>openssl genrsa 1024 -des3 > server.key

如果屏幕显示如下信息,则表明产生key成功:

Loading 'screen' into random state - done

Generating RSA private key, 1024 bit long modulus

.................++++++

....................................++++++

e is 65537 (0x10001)

      2、生成server.csr

输入F:\Apache2.2\bin>openssl req -new -key server.key > server.csr后,会产生如下的信息,要逐项填写,分别解释如下:

Loading 'screen' into random state - done

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or 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]:CN    国家代码,只支持两个字符

State or Province Name (full name) [Some-State]:SX 省份名称

Locality Name (eg, city) []:XA 城市名称

Organization Name (eg, company) [Internet Widgits Pty Ltd]:WWWW  组织名

Organizational Unit Name (eg, section) []:WWWW_XXZX  客户端证书所属的组织

Common Name (e.g. server FQDN or YOUR name) []:wwww.net 常用名,申请证书的域名比如完全限定域名

Email Address []:wwww@163.com  电子邮件

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:wwww  交换秘钥

An optional company name []:wwww

 

注意:Common Name必须和httpd.conf中的server name一致,否则apache不能启动。

 

      3、生成server.crt

F:\Apache2.2\bin>openssl req -x509 -days 365 -key server.key -in server.csr > server.crt

Loading 'screen' into random state - done

 

使用步骤12的秘钥和证书请求生产证书server.crt-days参数指定证书有效期,单位为天,x509表示生成的为X.509证书。

注意:上述签署证书仅仅做测试使用,真正运行时,需要将csr文件发送到一个CA,以返回真正的证书,使用openssl x509 -noout -text -in server.crt 可以查看证书内容,证书实际上包含了Public Key

 

    4、配置httpd.conf

将上述三个步骤中产生的文件拷贝到conf目录下。

打开httpd.conf文件,找到Include conf/extra/httpd-ssl.conf,将其前面的"#"去掉,

打开httpd-ssl.conf文件,找到以<VirtualHost _default_:443>,将其中的_default_替换为上述中输入的Common Name

SSLCertificateFile "D:/Apache2.2/conf/server.crt"

SSLCertificateKeyFile "D:/Apache2.2/ conf /server.key"

同时将httpd.conf中配置的关于JkMount的转发规则也配置到httpd-ssl.conf的相应位置

上述配置完成后,使用Test configuration来测试是否配置正确,如果正确,则弹出的窗口一闪而过,否则,弹出的窗口提示出错信息。

重新启动apache,使用https://wwww.net来访问,如果显示则表明配置正确。

猜你喜欢

转载自niweiwei.iteye.com/blog/1986017