One - One Code All

Blog Content

Apache服务httpd配置SSL证书以及HTTP重定向HTTPS

Linux-Mac   2013-09-15 22:48:16

Apache服务httpd配置SSL证书以及HTTP重定向HTTPS


apache https配置步骤

1、  确认是否安装ssl模块


是否有mod_ssl.so文件


ls /etc/httpd/modules


如果没有则先安装: yum install mod_ssl


2、  生成证书和密钥


linux下


步骤1:生成密钥


命令:openssl genrsa 1024 > server.key


说明:这是用128位rsa算法生成密钥,得到server.key文件


步骤2: 生成证书请求文件


命令:openssl req -new -key server.key > server.csr


说明:这是用步骤1的密钥生成证书请求文件server.csr, 这一步提很多问题,一一输入


步骤3: 生成证书


命令:openssl req -x509 -days 365 -key server.key -in server.csr > server.crt


说明:这是用步骤1,2的的密钥和证书请求生成证书server.crt,-days参数指明证书有效期,单位为天。


3、  配置apache


- 修改httpd-ssl.conf文件


注意在此文件中配置证书和密钥


SSLCertificateFile /etc/httpd/conf/server.crt

SSLCertificateKeyFile /etc/httpd/conf/server.key 


虚拟机设置

    DocumentRoot "test1"

    ServerName www.test1.com

    SSLEngine on

    SSLCertificateFile /etc/httpd/conf/server.crt

    SSLCertificateKeyFile /etc/httpd/conf/server.key



- 修改httpd.conf文件


步骤1:打开ssl模块


LoadModule ssl_module /opt/taobao/install/httpd/modules/mod_ssl.so


步骤2:引入ssl配置文件


Include “/apache/conf/httpd-ssl.conf”


步骤3:如果你配置的虚拟机,注意一下端口的访问接受情况


NameVirtualHost *:80



…………



4、  重新启动apache


用https方式访问,查看是否生效


 


5.HTTP重定向HTTPS

将所有到80端口(HTTP)的请求重写/重定向到443端口(HTTPS)即可,不要忘记ServerName应与443端口的配置一致


    RewriteEngine on

    RewriteCond %{SERVER_PORT} !^443$

    RewriteRule ^(.*)?$ https://%{SERVER_NAME}$1 [L,R]

    ServerName www.test1.com



上一篇:shell命令数值计算
下一篇:linux/mac替代makefile的编译工具Ninja介绍

The minute you think of giving up, think of the reason why you held on so long.