基于openssl搭建https服务器
1. 搭建web环境
我这里使用源码编译安装方式安装httpd。详情可以参加我的一篇博客http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_18_httpd.html
1.准备证书
详情可以参考我的另一篇文章 :http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_011_ca.html
1.1 创建必要的目录和文件
[root@localhost CA]# mkdir csr crl newcerts
[root@localhost CA]# touch index.txt serial
[root@localhost CA]# echo 01 >serial
1.2 修改默认配置
[root@localhost CA]# vim /etc/pki/tls/openssl.cnf
#编辑以下行, 设置默认的国家,省,城市,组织名,部门名
countryName_default = CN
stateOrProvinceName_default = HeNan
localityName_default = ZhengZhou
organizationName_default = ZKYT
organizationalUnitName_default = Tech
1.3生成自签证书
[root@localhost CA]# (umask ;openssl genrsa -out private/cakey.pem )
Generating RSA private key, bit long modulus
........................................................................................................................................+++
...+++
e is (0x10001)
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days
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 ( letter code) [CN]:
State or Province Name (full name) [HeNan]:
Locality Name (eg, city) [ZhengZhou]:
Organization Name (eg, company) [ZKYT]:
Organizational Unit Name (eg, section) [Tech]:
Common Name (eg, your name or your server's hostname) []:ca.linuxpanda.com
Email Address []:
1.4 创建证书请求
我们这里给web服务器创建一个证书请求。
[root@localhost CA]# cd /etc/httpd
[root@localhost httpd]# ls
extra httpd.conf magic mime.types original
[root@localhost httpd]# mkdir ssl
[root@localhost httpd]# cd ssl
[root@localhost ssl]# (umask ; openssl genrsa -out httpd.key )
Generating RSA private key, bit long modulus
..............+++
..............................................................+++
e is (0x10001)
[root@localhost ssl]# openssl req -new -key httpd.key -out 192.168.168.20.httpd.csr -days
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 ( letter code) [CN]:
State or Province Name (full name) [HeNan]:
Locality Name (eg, city) [ZhengZhou]:
Organization Name (eg, company) [ZKYT]:
Organizational Unit Name (eg, section) [Tech]:
Common Name (eg, your name or your server's hostname) []:www.linuxpanda.com
Email Address []: Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
1.5 复制证书请求到CA服务器上
root@localhost ssl]# scp 192.168.168.20.httpd.csr root@192.168.40.152:/tmp
The authenticity of host '192.168.40.152 (192.168.40.152)' can't be established.
RSA key fingerprint is :8d:9e::bf:::6a:6d:2f:cd:::c9:fd:.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.40.152' (RSA) to the list of known hosts.
192.168.168.20.httpd.csr % .0KB/s :
1.6 CA服务器签发证书
[root@localhost CA]# openssl ca -in /tmp/192.168.168.20.httpd.csr -out 192.168.168.20.crt
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: (0x1)
Validity
Not Before: Dec :: GMT
Not After : Dec :: GMT
Subject:
countryName = CN
stateOrProvinceName = HeNan
organizationName = ZKYT
organizationalUnitName = Tech
commonName = www.linuxpanda.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
::F1:F9:::8C::B6:E1:EB:AF:D4::AC:D9:::EB:
X509v3 Authority Key Identifier:
keyid:F4:::DD::3D::EC:::C5:BA:7C::C2:2F::A8:: Certificate is to be certified until Dec :: GMT ( days)
Sign the certificate? [y/n]:y out of certificate requests certified, commit? [y/n]y
Write out database with new entries
Data Base Updated
1.7 证书发送给web申请者
[root@localhost CA]# scp 192.168.168.20.crt root@192.168.168.20:/tmp
The authenticity of host '192.168.168.20 (192.168.168.20)' can't be established.
RSA key fingerprint is :8d:9e::bf:::6a:6d:2f:cd:::c9:fd:.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.168.20' (RSA) to the list of known hosts.
root@192.168.168.20's password:
192.168.168.20.crt % .4KB/s :
2. 配置web服务器支持https
2.1 编辑配置文件支持虚拟主机
[root@localhost extra]# vim /etc/httpd/extra/httpd-vhosts.conf
#添加如下行
<VirtualHost 192.168.168.152:80>
DocumentRoot "/var/www/www.linuxpanda.com"
ServerName www.linuxpanda.com
</VirtualHost>
<Directory /var/www/www.linuxpanda.com>
Require all granted
</Directory>
2.2 编辑配置文件支持https
[root@localhost extra]# vim /etc/httpd/extra/httpd-ssl.conf
#修改<VirtualHost _default_:> 为<VirtualHost 192.168.168.152:>
DocumentRoot "/var/www/www.linuxpanda.com"
ServerName www.linuxpanda.com:
ErrorLog "/var/www/www.linuxpanda.com/error_log"
TransferLog "/var/www/www.linuxpanda.com/access_log"
#修改httpd的私钥和证书文件位置
SSLCertificateKeyFile "/etc/httpd/ssl/httpd.key"
SSLCertificateFile "/etc/httpd/ssl/httpd.crt"
2.3 编辑配置文件httpd.conf
[root@localhost extra]# vim /etc/httpd/httpd.conf
#启用一下行
Include /etc/httpd24/extra/httpd-vhosts.conf
Include /etc/httpd24/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
#注释行
#DocumentRoot "/usr/local/apache/htdocs"
2.4 测试web服务
[root@localhost extra]# apachectl restart
#在我们测试机(windows主机的)的hosts文件中添加行
192.168.168.152 www.linuxpanda.com
浏览器输入http://192.168.168.152 即可看到 www.linuxpanda.com信息
在浏览器输入https://192.168.168.152 提示有警告信息。 证书不被信任的。 我们需要把ca服务器的cacert.pem 复制到测试机上,
重命名为cacert.crt文件, 双击安装,选择受信任的颁发机构即可。再次刷新发现可以正常访问了。
基于openssl搭建https服务器的更多相关文章
- 基于OpenSSL的HTTPS通信C++实现
HTTPS是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL.Nebula是一个为开发者提供一个快速开发 ...
- 其它 搭建https服务器
原因是这样的,做了个淘宝的数据管理系统(仅供自己使用),然后需要淘宝卖家的生意参谋里面的一些数据,比如实时访客,里面有每个用户搜索什么关键字进来的,这些信息. 自己基于CefSharp开发了一个win ...
- 利用nginx搭建https服务器
一.HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL / TLS,也就是在HTTP上又加了一层处理加密信息的模块.服务端和客户端的信息传输都会通过TLS进行加密,所以传输的数据都是加 ...
- windows环境下基于nginx搭建rtmp服务器
基于nginx搭建rtmp服务器需要引入rtmp模块,引入之后需重新编译nginx linux环境几个命令行就能实现编译,笔者未尝试,网上有很多教程. windows环境还需要安装一系列的编译环境,例 ...
- NodeJS搭建HTTPS服务器
[NodeJS搭建HTTPS服务器] http://cnodejs.org/topic/54745ac22804a0997d38b32d
- 关于搭建HTTPS服务器服务
关于 HTTPS 的基本原理大家都已经不再陌生,今天和大家说说如何搭建一个支持 HTTPS 的服务端. 服务端的 HTTPS HTTPS 已经几乎成为了当前互联网推荐的通信方式,它能最大化保证信息传输 ...
- Nginx搭建https服务器
HTTPS简介 HTTPS(Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单来讲就是HTTP的安全版.即H ...
- 使用nginx搭建https服务器
http://www.cnblogs.com/tintin1926/archive/2012/07/12/2587311.html 最近在研究nginx,整好遇到一个需求就是希望服务器与客户端之间传输 ...
- 信安实践——自建CA证书搭建https服务器
1.理论知识 https简介 HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HT ...
随机推荐
- P3047 [USACO12FEB]附近的牛Nearby Cows
https://www.luogu.org/problemnew/show/P304 1 #include <bits/stdc++.h> 2 #define up(i,l,r) for( ...
- 2019.03.28 bzoj3594: [Scoi2014]方伯伯的玉米田(二维bit优化dp)
传送门 题意咕咕咕 思路:直接上二维bitbitbit优化dpdpdp即可. 代码: #include<bits/stdc++.h> #define N 10005 #define K 5 ...
- Win7 VS2017编译Godot3.0.2和2.1.4
千呼万唤屎出来,Godot终于发布3.0版本的源码了,今天是2018年3月17日,自去年接触过后,一直没事就刷刷Gayhub,看看3.0什么时候更新,刷了一年也没结果. 今天上Youtube无意中搜了 ...
- JAVA 8 日期工具类
JAVA 8 日期工具类 主题描述 JAVA中日期时间的历史 代码成果 主题描述 JAVA的日期时间一直比较混乱,本来以为joda会是巅峰,但是JAVA 8改变了我的思想.但是即便在JAVA 8面前, ...
- Servlet的创建二以及生命周期
之前说Servlet可以通过实现Servlet接口来创建,但是我们看到了,需要重写该接口中的所有方法. 创建方式二:Servlet的创建还可以继承抽象类GenericServlet并重写其中的抽象方法 ...
- java性能分析工具
jcmd:向JVM发送诊断的命令,jvm未必会全部响应,有些需要在jvm开启相应功能才能响应.个人平时用的不是很多. SampleA: 添加 jcmd pid VM.native_mem ...
- OC字典的使用
在OC中,字符串.数组.字典是最常见的对象类型,但是在这三个当中,字典的用法相对较少,因为字典的属性和方法比较少,但是一个字典的用法比较复杂,因为在一个字典当中,既可以包含字符串,也可以包含数组,数组 ...
- xx系统属性分析
在本周的课程学习当中,我们简单了解到系统的一些属性,同时在课下也对<大型网站技术架构:核心原理与案例分析>进行了初步的阅读. 在书籍中我看到了许多其他的知识,也对课堂学习的知识有了巩固,现 ...
- grep,sed,awk用法整理
grep -c 打印出符合要求的行数 -i 忽略大小写 ignore -n 连同符号一起输出 num -v 打印出不符合要求的行 -A2 本行及下面两行 - ...
- 简单了解Django
Django 是开源代码web应用的框架,由python完成,django的主要目的是简便,快速开发数据库驱动网站 主要用于测试,运维,自测. 1.下载Django. 个人建议使用命令pip inst ...