Technology Sharing

Use Linux's openssl to generate an ssl key for https, and then sign it yourself

2024-07-06

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Create a new folder

mkdir all_https_ssl
cd all_https_ssl

first step:

Generate a key with a custom length, such as 2048 (to prevent some applications from requiring the key length to be too short)

openssl genrsa -out key.pem 2048

Step 2:

Use the private key to generate a certificate request (the CSR certificate request is used to send it to the visa company to generate a certificate)

openssl req -new -key key.pem -out csr.pem

Then you will be asked to enter your signature information.
Note: You can fill in CN for the country, and do not fill in the other fields. Do not fill in the password. Press Enter to jump to the end.

third step:

Use CSR certificate request to sign (sign by yourself, no need to issue the certificate company, sign for 30 years)

openssl x509 -req -in csr.pem -out cert.pem -signkey key.pem -days 9650

the fourth step:

Configure the certificate key and cert to the ssl of port 443 of nginx (nginx's https must be configured with ssl_certificate)

server {
	listen 443;
	server_name your-domain.com;
	
	ssl on;
	
	ssl_certificate /path/to/cert.pem;
	ssl_certificate_key /path/to/key.pem;
}