天天看点

Apache配置SSLApache配置SSL

Apache配置SSL

第一步

在httpd.conf配置文件中开启

开启载入ssl配置文件 如果没有这一行,复制到httpd.conf文件末尾

Include conf/extra/httpd-ssl.conf
           
第二步 自己生成证书文件

首先切换到apache安装目录

Apache配置SSLApache配置SSL

生成服务器密匙

生成签署申请 执行这一条命令需要输入一些信息

Apache配置SSLApache配置SSL
Country Name (2 letter code) [AU]:CN                /*国家代码*/
State or Province Name (full name) [Some-State]:Beijing     /*省*/
Locality Name (eg, city) []:beijing             /*地名*/
Organization Name (eg, company) [Internet Widgits Pty Ltd]:jokechat.cn /*你的域名*/
Organizational Unit Name (eg, section) []:IT Dept           /*组织单位名称*/
Common Name (e.g. server FQDN or YOUR name) []:jokechat.cn              /*普通名称*/
Email Address []:[email protected]                    /*邮箱地址*/

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:                              /*设置密码*/
An optional company name []:jokechat.cn                 /*我设置公司名称*/
           

生成CA私钥

利用CA的私钥产生CA的自签署证书 这一步也需要输入一些信息 参照以上即可

openssl req  -new -x509 -days  -key ca.key -out ca.crt  -config ..\conf\openssl.cnf
           

为网站服务器签署证书 执行此命令会报错 需要在此目录下创建两层目录,两个文件

Apache配置SSLApache配置SSL
  • newcerts

    空目录

  • index.txt

    新建文件 无需填写内容

  • serial

    文件内容为01

现在执行则没有问题了

现在已经生成了证书文件

第三步 apache ssl配置文件修改
SSLCertificateFile "D:/WWW/Apache/conf/2_jokechat.cn.crt"
/* #SSLCertificateFile "D:/WWW/Apache/conf/server-dsa.crt" */

SSLCertificateKeyFile "D:/WWW/Apache/conf/3_jokechat.cn.key"
/* ##SSLCertificateKeyFile "D:/WWW/Apache/conf/server-dsa.key"  */

SSLCertificateChainFile "D:/WWW/Apache/conf/1_root_bundle.crt"
           

然后重新启动Apache服务就可以了

最后效果如下

Apache配置SSLApache配置SSL

如果想在本地进行测试不要忘记修改hosts

如果想在网络上同行 有很多形式可以免费获得认证证书

例如:CA 沃通免费SSL证书 有兴趣者可以自行尝试