[root@ha02 keys]# openssl genrsa -out www.app01.com.key 2048 Generating RSA private key, 2048 bit long modulus ....+++ .....................................+++ e is 65537 (0x10001) [root@ha02 keys]# openssl req -new -key www.app01.com.key -out www.app01.com.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 (2 letter code) [XX]:CN State or Province Name (full name) []:BeiJing Locality Name (eg, city) [Default City]:BeiJing Organization Name (eg, company) [Default Company Ltd]:espressos.cn Organizational Unit Name (eg, section) []:app Common Name (eg, your name or your server's hostname) []:www.app01.com Email Address []:ck@.163.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: [root@ha02 keys]# ls www.app01.com.csr www.app01.com.key
[root@ha02 keys]# openssl x509 -req -days 365 -in www.app01.com.csr -signkey www.app01.com.key -out www.app01.com.crt Signature ok subject=/C=CN/ST=BeiJing/L=BeiJing/O=espressos.cn/OU=app/CN=www.app01.com/emailAddress=ck@.163.com Getting Private key
[root@ha02 keys]# cat www.app01.com.crt www.app01.com.key |tee www.app01.com.pem -----BEGIN CERTIFICATE----- MIIDkjCCAnoCCQDXDebyNmUGrDANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC Q04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcxFTATBgNVBAoM DGVzcHJlc3Nvcy5jbjEMMAoGA1UECwwDYXBwMRYwFAYDVQQDDA13d3cuYXBwMDEu Y29tMRowGAYJKoZIhvcNAQkBFgtja0AuMTYzLmNvbTAeFw0xNjEyMTcyMDU5MzRa Fw0xNzEyMTcyMDU5MzRaMIGKMQswCQYDVQQGEwJDTjEQMA4GA1UECAwHQmVpSmlu ZzEQMA4GA1UEBwwHQmVpSmluZzEVMBMGA1UECgwMZXNwcmVzc29zLmNuMQwwCgYD VQQLDANhcHAxFjAUBgNVBAMMDXd3dy5hcHAwMS5jb20xGj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WC3sEaTd36Hi7dvye/jXN8UiLecgaKjjjRhKqp68TnRbwV5MioFjTvn 1fQDOQl1vSkmPDiZ6iQVfDXN0EuECSWk0gy8fhicR2CrzoMn1sbO2tTwjujns4EN 5NhHYQ0CgYEAlp6XGwJ+Dih/uQgrRQA5BXB3GYlYpMOEUNJk/3oWh+tl+/vzPRjy IEZ9jsJ7E3DGhWC9l/MTY8rWEq30B8Qca9trZilcKgLTlHUIVQJnlkLAS3t+48qa faL1ev3/gJMIw06u/OT8Yl5D8ZzyK1R4YDvjOusdpfRSE6Jwq9Wrgoo= -----END RSA PRIVATE KEY-----
[root@ha02 keys]# ls
www.app01.com.crt www.app01.com.csr www.app01.com.key www.app01.com.pem
按照以上方法依次生www.app02.com.pem
[root@ha02 keys]# openssl genrsa -out www.app02.com.key 2048 Generating RSA private key, 2048 bit long modulus ..........................................................................+++ ..................................+++ e is 65537 (0x10001) [root@ha02 keys]# openssl req -new -key www.app02.com.key -out www.app02.com.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 (2 letter code) [XX]:CN State or Province Name (full name) []:BeiJing Locality Name (eg, city) [Default City]:BeiJing Organization Name (eg, company) [Default Company Ltd]:espressos Organizational Unit Name (eg, section) []:espressos Common Name (eg, your name or your server's hostname) []:www.app02.com Email Address []:ck@163.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: [root@ha02 keys]# ls www.app01.com.crt www.app01.com.key www.app02.com.csr www.app01.com.csr www.app01.com.pem www.app02.com.key
[root@ha02 keys]# openssl x509 -req -days 365 -in www.app02.com.csr -signkey www.app02.com.key -out www.app02.com.crt Signature ok subject=/C=CN/ST=BeiJing/L=BeiJing/O=espressos/OU=espressos/CN=www.app02.com/emailAddress=ck@163.com Getting Private key [root@ha02 keys]# cat www.app02.com.crt www.app02.com.key |tee www.app02.com.pem -----BEGIN CERT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B78sdWvNN1WF/fRFxqJOSSuPoYjsTBfbfzw8AUTrAoGBAMbd aRcrid9yRZ+ZSk5ut5gxjyZT/fpZdCpwuTRWGwHuDT+PtAtJHicq9OWp41RrlK15 C5hX8d2M7NxpJPf0lQP7KLUd3QSEpoXlRLyAXDgAKpQJKf01nU5rnk7Z3pUs616Q tHhyUm/OojcMzYHpwib86TfZf42uNavqeQMtU0ihAoGAGSb1WBAbBf6wcDXitnv+ 3GOgh6rntlUQBbjfMJn/6vef4oTJQNKNUctgI5KvV539tA6oD8vxlM4NIpg80Y1v saQDH03ZdwozdLV/TkcqK5E4P3YIMp/e3k4IPVpg31/Zgv10K/5ZoWDgXwhrhtW4 xQXQ8UDoFoqisl5ddC0q20cCgYA9TozTY8zBYg0swqkxvNhExyKGgmZOA73YR6AR DmqNEcJr0fWDdSsikA+nrdQzdmcDg8mbUaFy17s9x/xppLE75PYLwAUfG3Xq2V9z bW8ApKx7rsePFDRGtM69KFWCT7LQGHRKnZPkfCNuLTg90L7WHioX2amFGCvbsBFW dWazgQKBgCNS9WU81O67RnE18ymcjzmogBCV1us1SxaWQ7zJZwAc5of8717TqB+l ZSgPkb8aSkQIVBp3qKYOgNn51/WK6fSFE2jKVQFHCGrVcs7f1Ofru3Wey38qMZ0y xz5HBI0G/G+ICzsQwTUNTjw2vcUWWwV4jaKpQkOGUlcJVDIJO/l6 -----END RSA PRIVATE KEY----- [root@ha02 keys]# ls www.app01.com.crt www.app01.com.key www.app02.com.crt www.app02.com.key www.app01.com.csr www.app01.com.pem www.app02.com.csr www.app02.com.pem
[root@ha02 haproxy-1.4.26]# cat conf/haproxy.cfg global log 127.0.0.1 local0 info maxconn 51200 user nobody group nobody daemon nbproc 1 pidfile /var/run/haproxy.pid defaults log global option tcplog option httpclose option forwardfor except 127.0.0.0/8 option redispatch option dontlognull retries 3 timeout client 1m timeout server 1m timeout http-request 10s timeout http-keep-alive 10s timeout queue 1m maxconn 10000 listen admin_stats bind 0.0.0.0:8000 stats refresh 30s stats uri /vip stats realm hello chenlin stats auth admin:admin@! stats hide-version stats admin if TRUE mode http #server sshd 192.168.1.104:22 check port 22 inter 5000 fall 5 frontend www.app01.com mode http bind 0.0.0.0:443 ssl crt /etc/ssl/keys/www.app01.com.pem crt /etc/ssl/keys/www.app02.com.pem use_backend www_app01_com if { ssl_fc_sni www.app01.com } use_backend www_app02_com if { ssl_fc_sni www.app02.com } backend www_app01_com mode http server app01 192.168.1.108:8010 backend www_app02_com mode http server app02 192.168.1.109:8020
haproxy 实现了多域https
[root@ha02 haproxy-1.5.2]# ./sbin/haproxy -v HA-Proxy version 1.5-dev19 2013/06/17 Copyright 2000-2013 Willy Tarreau <w@1wt.eu>