电源柜厂家
免费服务热线

Free service

hotline

010-00000000
电源柜厂家
热门搜索:
技术资讯
当前位置:首页 > 技术资讯

Linux系统ApacheSSL安装与配置

发布时间:2020-02-10 19:11:08 阅读: 来源:电源柜厂家

kylin:apache是很流行的,但是在linux下安装apache ssl的文章并没有很多详细的,此文写的比较详细了,分享给大家。

互联网的线路侦听无处不在,明文传输的数据一不留神就可能被窃取。而Apache的SSL加密连接可以帮助浏览者更加安全可靠的传输数据。通常来 说,普通的HTTP协议URL是以http:// 开头,而SSL加密协议则是以https:// 开头。本文将介绍CentOS系统下通过仓库(yum、apt-get)配置apache中SSL加密模块的方法。

实验环境:

CentOS release 5.7 (Final)

Apache/2.2.3

首先安装Apache

1 [root@www ~]# yum install httpd

大多数情况下,安装Apache需要附带安装好php、Mysql等模块。

部署好Apache环境后,开始

安装SSL模块

1 [root@www ~]# yum install mod_ssl

安装完成,直接重启Apache服务:

1 [root@www ~]# /etc/init.d/httpd restart

由于安装mod_ssl会创建一个默认的SSL证书,路径位于/etc/pki/tls ,此时可以立即通过https访问服务器了:

https://IP/

如果不使用默认的证书,也可以使用OPENSSL手动创建证书。

使用OPENSSL手动创建证书

先执行以下命令安装OPENSSL:

1 [root@www ~]# yum install openssl

完成后即可按照以下步骤生成证书文件:

1、创建私钥

1 [root@www ~]# openssl genrsa -out y 1024

2、用私钥y 文件生成证书签署请求CSR

1 [root@www ~]# openssl req -new -key y -out r

此步骤需要输入一些证书信息,解释如下:

Country Name (2 letter code) [GB]:【在此输入两个字符的国家名。中国的为CN 】

State or Province Name (full name) [Berkshire]:【省份名称,如北京为beijing 】

Locality Name (eg, city) [Newbury]:【城市名称,如beijing】

Organization Name (eg, company) [My Company Ltd]:【公司名称】

Organizational Unit Name (eg, section) []:【部门名称】

Common Name (eg, your name or your server's hostname) []:【姓名,通常即证书名】

Email Address []:【电子邮箱地址】

随后会要求输入一个challenge password(密码),无需输入,后面一律直接回车即可。

3、生成证书CRT文件

1 [root@www ~]# openssl x509 -days 3650 -req -in r -signkey y -out t

上面生成的证书有效期为10年(呵呵太长了点,一般三年就行了)

这时证书的相关文件就都已经生成好了。当前文件夹下应该有t、r、y这三个文件。

如果你是个完美论者,理所当然应该把这三个文件丢到证书的"官方目录"中去,省的把文件胡乱放置以后找不着:

1 [root@www ~]# mkdir /etc/pki/tls/mycert

2 [root@www ~]# mv server.* /etc/pki/tls/mycert

最后仅仅需要修改配置文件来指定证书路径:

4、指定证书路径

打开Apache的SSL配置文件/etc/httpd/conf.d/nf :

1 [root@www ~]# vi /etc/httpd/conf.d/nf

找到如下一节:

# Server Certificate:

# Point SSLCertificateFile at a PEM encoded certificate. If

# the certificate is encrypted, then you will be prompted for a

# pass phrase. Note that a kill -HUP will prompt again. A new

# certificate can be generated using the genkey(1) command.

SSLCertificateFile /etc/pki/tls/mycert/t

# Server Private Key:

# If the key is not combined with the certificate, use this

# directive to point at the key file. Keep in mind that if

# you've both a RSA and a DSA private key you can configure

# both in parallel (to also allow the use of DSA ciphers, etc.)

SSLCertificateKeyFile /etc/pki/tls/mycert/y

注意红色的文字修改的部分。保证其路径分别指向刚刚创建的t与y即可。

5、重启Apache2

1 [root@www ~]# /etc/init.d/httpd restart

这时新的证书便已经生效了。刷新浏览器,点击浏览器中的证书标志,便可以看到刚刚制作的证书信息:

濑亚美莉ed2k

杉原杏璃av

唯美爱情语录