mkdir /etc/ssl/xip.io
[root@ha02 haproxy-1.4.]# openssl genrsa -out /etc/ssl/xip.io/xip.io.key
Generating RSA private key, bit long modulus
........++++++
...........++++++
e is (0x10001)
[root@ha02 haproxy-1.4.]# openssl req -new -key /etc/ssl/xip.io/xip.io.key -out /etc/ssl/xip.io/xip.io.csr
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) [XX]:CN #国家代码
State or Province Name (full name) []:china #省
Locality Name (eg, city) [Default City]:beijing #市
Organization Name (eg, company) [Default Company Ltd]:iseastar #公司名称
Organizational Unit Name (eg, section) []:iseastar #可以不写
Common Name (eg, your name or your server's hostname) []:iseastar #可以不写
Email Address []: #邮箱地址 Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@ha02 haproxy-1.4.]# openssl x509 -req -days  -in /etc/ssl/xip.io/xip.io.csr -signkey /etc/ssl/xip.io/xip.io.key -out /etc/ssl/xip.io/xip.io.crt
Signature ok
subject=/C=CN/ST=china/L=beijing/O=iseastar/OU=iseastar/CN=iseastar
Getting Private key

这样就生成了下面的三个文件:

[root@ha02 haproxy-1.4.]# tree /etc/ssl/xip.io/
/etc/ssl/xip.io/
├── xip.io.crt
├── xip.io.csr
└── xip.io.key directories, files

在创建了证书之后,我们需要创建pem文件。pem文件本质上只是将证书 密钥及证书中心证书(可有可无)拼接成一个文件。在我们在这里只是简单地将证书及密钥文以这个顺序拼接在起来创建xip.io.pen文件 。这就是HAProxy读取SSL证书首选的方式。

[root@ha02 haproxy-1.4.]# cat /etc/ssl/xip.io/xip.io.crt /etc/ssl/xip.io/xip.io.key |tree /etc/ssl/xip.io/xip.io.pem
/etc/ssl/xip.io/xip.io.pem [error opening dir] directories, files
[root@ha02 haproxy-1.4.]# ls /etc/ssl/xip.io/
xip.io.crt xip.io.csr xip.io.key
有报错,并没有生成.pem结尾的文件

后来细心看一下一个命命看错了应该是tee而不是tree

[root@ha02 haproxy-1.4.]# cat /etc/ssl/xip.io/xip.io.crt /etc/ssl/xip.io/xip.io.key |tee /etc/ssl/xip.io/xip.io.pem
-----BEGIN CERTIFICATE-----
MIICRzCCAbACCQCp15MeAY6YFzANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJD
TjEOMAwGA1UECAwFY2hpbmExEDAOBgNVBAcMB2JlaWppbmcxETAPBgNVBAoMCGlz
ZWFzdGFyMREwDwYDVQQLDAhpc2Vhc3RhcjERMA8GA1UEAwwIaXNlYXN0YXIwHhcN
MTYxMjE2MDUxMzM5WhcNMTcxMjE2MDUxMzM5WjBoMQswCQYDVQQGEwJDTjEOMAwG
A1UECAwFY2hpbmExEDAOBgNVBAcMB2JlaWppbmcxETAPBgNVBAoMCGlzZWFzdGFy
MREwDwYDVQQLDAhpc2Vhc3RhcjERMA8GA1UEAwwIaXNlYXN0YXIwgZ8wDQYJKoZI
hvcNAQEBBQADgY0AMIGJAoGBANEKpgCx8Hd0J2gZd/YJRpqjac0nZNU29pyOpXbl
VxOy9tUR4bHX6y7IDW/G297orwc2AIGetNVSYEVKTh6pCZz6H/E+FZG7+A2ftJ8I
823Hx7iW10Q1sP95UsYB2N0wd5AtKfywuv3Bjwe2nQj3R47+LuwABNnXS0mYp93y
4EkxAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEABd+XL1YdowVUWivoxki751bAdqpv
L9WizV1LW0Whf4GWS10wnubXSOHqR3Ybcm9Nnq1adqoV1g8pcJMWGYk+JKjA+N+i
tiiBSwvKw7kEC3/r2EH0vmVtv4TLcohTJrIil2WslPYcHVcWJX/HdgBD5yhSNp4D
INwzh2GWxZ2HAE8=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDRCqYAsfB3dCdoGXf2CUaao2nNJ2TVNvacjqV25VcTsvbVEeGx
+suyA1vxtve6K8HNgCBnrTVUmBFSk4eqQmc+h/xPhWRu/gNn7SfCPNtx8e4ltdE
NbD/eVLGAdjdMHeQLSn8sLr9wY8Htp0I90eO/i7sAATZ10tJmKfd8uBJMQIDAQAB
AoGAc8J10wS2qS/FcrxH1hOk6ZV8zYL3L6tUPbYwovq1kc8VKUDRvu5W6n0WE8QH
lhU8d73L4fvFICyR600OnaP2EdtslR0BLwR0r55PMGxm6hpE5KI8N3nrxRQSkbPs
u8o9rS9IaWXjKk5gYcrTQTfGuaez4TzsUtQr/oVJfviZ25ECQQDxq/ZpTzbr6TFH
V+iLFI3dwz6wH72DTFPo5FrZ+s7VTuuYi8mb1LDxXFxWKCgaD1vAZf8hFddXthjA
20Kk7+DXAkEA3W9u7VWa6C85NbGQ6VH6AVSk9uDgzWafxWw0in3tdsV/VEZxu3PF
iXFHVHUhy4dc7UZksl7GACtkPiMV6iJ9NwJBAJpNZYNPpI1z0pbutfc3JG1XYAsr
+OCAN4MXajqLPMxNG3fGqO7qGh/BDOOluBULgVWSyhbhzyCdj6hzVlXhIvkCQF2k
mVGO6TKVfekiDXlOLJ7Rb+3jjc3vP1Pa/aEvvfODc+Rs4f326KvGFvc1jbQnq3nA
UidIgw1hTEQmzEa2jSMCQGDoM8ginUV7o33WcKLog5arhYFVOXuZi478GAhtauX9
Dcv8CRWpfdi3LuOM8yCRWDEyPfBw+3CfIBlXjVBkD7w=
-----END RSA PRIVATE KEY-----
[root@ha02 haproxy-1.4.]# tree /etc/ss
ssh/ ssl/
[root@ha02 haproxy-1.4.]# tree /etc/ssl/xip.io/
/etc/ssl/xip.io/
├── xip.io.crt
├── xip.io.csr
├── xip.io.key
└── xip.io.pem directories, files

当购买真正的证书时,你不一定会获取并接后的文件。可能需要自己拼接生成,但也有机构提供拼接好的文件 给你。但可能不是pem文件,而是dundel ,cert, cert, key文件或一些相同概念但名称类似的文件。

pem文件是HAProxy只需简单配置就可以处理SSLL连接了。

要在HAProxy使用SSL连接 ,我们现在就可以添加校准SSL端口443的绑定,并让HAProxy知道SSL证书的位置 :

         stats admin if TRUE                               |          stats admin if TRUE
mode http | mode http
#server sshd 192.168.1.104: check port inter | #server sshd 192.168.1.104: check port inter
|
frontend app01_www.app01.com: | frontend app01_www.app01.com:
bind *: | bind *:
bind *: ssl crt /etc/ssl/xip.io/xip.io.pem | ---------------------------------------------------------
timeout client 8h | timeout client 8h
mode http | mode http
default_backend server_app01 | default_backend server_app01
backend server_app01 | backend server_app01
mode http | mode http
timeout server 8h | timeout server 8h
cookie SERVERID insert nocache | cookie SERVERID insert nocache
server app01 10.100.0.37: check port rise| server app01 10.100.0.37: check port ris
frontend app02_www.app02.com: | frontend app02_www.app02.com:
bind *: | bind *:
bind *: ssl crt /etc/ssl/xip.io/xip.io.pem | ---------------------------------------------------------
timeout client 8h | timeout client 8h
mode http | mode http
default_backend server_app02 | default_backend server_app02
backend server_app02 | backend server_app02
mode http | mode http
timeout server 8h | timeout server 8h
+ +-- lines: cookie SERVERID insert nocache--------------|+ +-- lines: cookie SERVERID insert nocache-------------

看看下在的改动只是加了一行代码:

 bind *: ssl crt /etc/ssl/xip.io/xip.io.pem 

上面的配置可以支持https也支持http

下面只支持https,看一下这三个文件的不同:

+ +--  lines: global--------------------------------------|+ +--  lines: global-------------------------------------
mode http | mode http
#server sshd 192.168.1.104: check port inter | #server sshd 192.168.1.104: check port inter
|
frontend app01_www.app01.com: | frontend app01_www.app01.com:
bind *: | bind *:
bind *: ssl crt /etc/ssl/xip.io/xip.io.pem | bind *: ssl crt /etc/ssl/xip.io/xip.io.pem
redirect scheme https if !{ ssl_fc } | ---------------------------------------------------------
timeout client 8h | timeout client 8h
mode http | mode http
default_backend server_app01 | default_backend server_app01
backend server_app01 | backend server_app01
mode http | mode http
timeout server 8h | timeout server 8h
cookie SERVERID insert nocache | cookie SERVERID insert nocache
server app01 10.100.0.37: check port rise| server app01 10.100.0.37: check port ris
frontend app02_www.app02.com: | frontend app02_www.app02.com:
bind *: | bind *:
redirect scheme https if !{ ssl_fc } | ---------------------------------------------------------
bind *: ssl crt /etc/ssl/xip.io/xip.io.pem | bind *: ssl crt /etc/ssl/xip.io/xip.io.pem
timeout client 8h | timeout client 8h
mode http | mode http
default_backend server_app02 | default_backend server_app02
backend server_app02 | backend server_app02
mode http | mode http
+ +-- lines: timeout server 8h---------------------------|+ +-- lines: timeout server 8h--------------------------

前左边的只支持https右边是支持https和http

ca 自签名证书 并实现HAProxy https功能的更多相关文章

  1. 自签名证书安全性问题研究https(ssl)

    先看下https(ssl)的好处,以及为什么要用: http://imweb.io/topic/565c71673ad940357eb99879 https://zh.wikipedia.org/wi ...

  2. 生成自签名证书-开启https

    1.生成CA证书 # 生成 CA 私钥 openssl genrsa -out ca.key 2048 # X.509 Certificate Signing Request (CSR) Manage ...

  3. CA证书、自颁发证书、自签名证书联系

    一.理论基础 ssl:secure socket layer(安全套接层协议)的缩写,通过此协议可以保证两个应用通信的可靠性和保密性.openssl:是ssl协议的实现.提供了对称加密算法.非对称加密 ...

  4. Docker registry自签名证书

    权威Registry 获取安全证书有两个办法:互联网认证的CA处获取.自建CA自己给自己签名. 1.从认证CA处获取签名证书,大多数是需要付出一定费用的,近些年也有认证CA提供免费证书,例如Let’s ...

  5. Windows Server 2008 R2 下配置TLS1.2,添加自签名证书

    前言 2017年1月1日起App Store上的所有App应用将强制开启ATS功能. 苹果的ATS(App Transport Security)对服务器硬性3点要求: ① ATS要求TLS1.2或者 ...

  6. openssl生成自签名证书

    1.生成x509格式的CA自签名证书 openssl req -new -x509 -keyout ca.key -out ca.crt 2.生成服务端的私钥(key文件)及申请证书文件csr文件 o ...

  7. mac 浏览器(chrome, safari)信任自签名证书

    mac 浏览器(chrome, safari)信任自签名证书 自签名证书创建了一个 https 服务器,但是浏览器访问的时候总是不信任证书,感觉很烦,就想如果信任这个证书就不会有问题了. 方法1: 直 ...

  8. Linux操作系统安全-局域网私有CA(Certificate Authority)证书服务器实战篇

    Linux操作系统安全-局域网私有CA(Certificate Authority)证书服务器实战篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.试验架构说明 node101 ...

  9. Nginx 高级配置-https 功能

    Nginx 高级配置-https 功能 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HTTPS工作过程 1>.SSL/TLS SSL(Secure Socket Lay ...

随机推荐

  1. Angular 2 - 5 分钟快速入门

    原文地址: https://angular.io/docs/ts/latest/quickstart.html 让我们从 0 开始创建一个简单的 Angular 2 应用. 下载任何版本的 angul ...

  2. UI: 窗口全屏, 窗口尺寸

    窗口全屏 窗口尺寸 示例1.窗口全屏UI/FullScreen.xaml <Page x:Class="Windows10.UI.FullScreen" xmlns=&quo ...

  3. jquery 离开页面提示信息

    <script> $(window).bind('beforeunload', function () { return '您输入的内容尚未保存,确定离开此页面吗?'; });</s ...

  4. python对缓存(memcached,redis)的操作

    1.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...

  5. TypeScript Writing .d.ts files(编写声明文件)

    当使用扩展的JavaScript库或者插件API的时候,将需要使用声明文件(.d.ts)来描述库的类型.本文内容将包括如何编写声明文件相关的一些高级概念,然后用一些例子来展示如何将各式各样的概念与声明 ...

  6. Windows中创建桌面快捷方式

    Windows中创建桌面快捷方式 -------------- -------------- -------------- --------------

  7. fatal: could not read Username for 'https://github.com': No such file or directo

    Git push origin master报错 fatal: could not read Username for 'https://github.com': No such file or di ...

  8. QT中使用函数指针

    想仿命令行,所以定义了一个类,让一个String 对应一个 function,将两者输入list容器. 类中定义了 QString commandStr; void (MainWindow::*com ...

  9. [Centos]升级安装GCC

    摘要 在尝试运行asp.net core站点的时候,发现了gcc包版本太低,造成一些错误.没办法只能升级gcc了. 升级 最新包:http://gcc.parentingamerica.com/rel ...

  10. 【08-23】redis学习笔记

    今天开始重拾linux,使用的是ubuntu发行版,主要是想在linux上学习redis,作为服务器端软件天然选择linux啊. 第一次使用ubuntu配置超级管理员密码: su passwd roo ...