Skip to content

Instantly share code, notes, and snippets.

@yuezhu
Created February 7, 2018 18:10
Show Gist options
  • Save yuezhu/47b15b4b8e944221861ccf7d7f5868f5 to your computer and use it in GitHub Desktop.
Save yuezhu/47b15b4b8e944221861ccf7d7f5868f5 to your computer and use it in GitHub Desktop.
Generate self-signed certificate for HAProxy
# Generate a unique private key (KEY)
sudo openssl genrsa -out mydomain.key 2048
# Generating a Certificate Signing Request (CSR)
sudo openssl req -new -key mydomain.key -out mydomain.csr
# Creating a Self-Signed Certificate (CRT)
openssl x509 -req -days 365 -in mydomain.csr -signkey mydomain.key -out mydomain.crt
# Append KEY and CRT to mydomain.pem
sudo bash -c 'cat mydomain.key mydomain.crt >> /etc/ssl/private/mydomain.pem'
# Specify PEM in haproxy config
sudo vim /etc/haproxy/haproxy.cfg
listen haproxy
bind 0.0.0.0:443 ssl crt /etc/ssl/private/mydomain.pem
@phacic
Copy link

phacic commented Feb 10, 2019

Thanks I needed this

@joshzcold
Copy link

This helped me out. tutorials seem to give out too much information

@ajithchanaka
Copy link

Thanks it was helpfull.

@chuhakhanh
Copy link

thank I just use it to test. It fix my problem for create .pem wrong.

@erick-rangel-movile
Copy link

Maybe is it missing a sudo on line 8?

@aentrepreneur
Copy link

Thanks, I was looking for this...

@Jagadeeshrj21
Copy link

Much needed information

@D-saif
Copy link

D-saif commented Jan 31, 2022

thank you it was helpful.
PS: sudo is missing on line 8

@Youngwoo-Grit-Yoon
Copy link

You have saved my life! Thank you so much, brother.

@LittleSaya
Copy link

Thank you, it works perfectly!

@kkurzacz-intel
Copy link

I recommend use of single inequality sign (>) instead of double (>>) in line 11:

sudo bash -c 'cat mydomain.key mydomain.crt > /etc/ssl/private/mydomain.pem'

If you do mistake in previous key or cert file and run this command with double ones, it will append to file instead of overriding. In my case it lead to confusing errors of "inconsistencies between private key and certificate".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment