系统环境为:
JAVA:jdk1.6.0_30
System:CentOSrelease5.7
Apache:httpd-2.2.3
Openssl:openssl-0.9.8e
网络上该类文档多为指导测试用的SSL配制,商用SSL一般需要权威的第三方机构认证,IE浏览器才不提示证书无效。
1.安装Apache与OpenSSL:
略。其中Apache需使用带有MOD_SSL模块的版本
2.KEY生成:
进入/usr/local/httpd/conf/sign目录下执行按顺序执行以下命令:
1>opensslgenrsa-des31024>/usr/local/httpd/conf/server.key←建立服务器密钥
GeneratingRSAprivatekey,1024bitlongmodulus…………….++++++…………………………………………………………………++++++eis65537(0x10001)Enterpassphrase: ←在这里输入口令
Verifying–Enterpassphrase: ←确认口令,再次输入
2>opensslrsa-in/usr/local/httpd/conf/server.key>/usr/local/httpd/conf/server2.key←从密钥中删除密码(以避免系统启动后被询问口令)
Enterpassphraseforssl.key/server.key: ←输入口令writingRSAkey
3>mv/usr/local/httpd/conf/server2.key/usr/local/httpd/conf/server.key
4>opensslreq-new-key/usr/local/httpd/conf/server.key-out/usr/local/httpd/conf/server.csr←建立服务器密钥请求文件
Youareabouttobeaskedtoenterinformationthatwillbeincorporatedintoyourcertificaterequest.WhatyouareabouttoenteriswhatiscalledaDistinguishedNameoraDN.TherearequiteafewfieldsbutyoucanleavesomeblankForsomefieldstherewillbeadefaultvalue,Ifyouenter‘.’,thefieldwillbeleftblank.—–
CountryName(2lettercode)[GB]:CN ←输入国名
StateorProvinceName(fullname)[Berkshire]:GD ←输入省名
LocalityName(eg,city)[Newbury]:Foshan ←输入城市名
OrganizationName(eg,company)[MyCompanyLtd]:cdcgs←输入组织名(任意)
OrganizationalUnitName(eg,section)[]: ←不输入,直接回车
CommonName(eg,yournameoryourserver’shostname)[]:www. ←输入通称(任意)
EmailAddress[]:yourname@ ←输入电子邮箱地址
Pleaseenterthefollowing‘extra’attributestobesentwithyourcertificaterequestAchallengepassword[]: ←不输入,直接回车Anoptionalcompanyname[]: ←不输入,直接回车
5>opensslx509-in/usr/local/httpd/conf/server.csr-out/usr/local/httpd/conf/server.crt-req-signkey/usr/local/httpd/conf/server.key-days365←建立服务器证书
Signatureoksubject=/C=CN/ST=GD/L=Foshan/O=cdcgs/CN=www./emailAddress=yourname@GettingPrivatekey
3.Apache添加SSL支持:
1>关闭Apache:
./usr/local/httpd/bin/httpd–kstop
2>增加支持SSL,执行 vi/usr/local/httpd/conf/httpd.conf:
#Includeconf/extra/httpd-ssl.conf←找到这一行,将行首的“#”去掉
↓
Includeconf/extra/httpd-ssl.conf
3>启动重定向(可选),使用用户HTTP访问自动重定向为HTTPS,在httpd.conf文件尾加入如下内容:
RewriteEngineon
RewriteCond%{SERVER_PORT}!^443$
RewriteRule^/?(.*)$https://%{SERVER_NAME}/$1[L,R]
4>设置加密文件,在文件/usr/local/httpd/conf/extra/httpd-ssl.cnf中,将以下几行的注释去掉,并修改相应路径如下:
SSLCertificateFile“/usr/local/httpd/conf/sign/server.crt”
SSLCertificateKeyFile“/usr/local/httpd/conf/sign/server.key”
DocumentRoot“/srv/com.iaspec/saas/live”
4.启动apache:
./usr/local/httpd/bin/httpd–kstart
5.测试HTTPS:
打开浏览器,在地址栏输入“http://你的域名”或者“https://你的域名”后,如果浏览器自动跳转成htts://…,并且能继续访问成功,则表示服务器已经可以支持SSL.
猜你喜欢