Linux uses OpenSSL to generate SSL certificates for Nginx to use

Source: Internet
Author: User
Tags openssl openssl rsa openssl x509

Here's how Linux systems generate certificates through the OpenSSL command.

First, execute the following command to generate a 4,096-bit key

The code is as follows Copy Code

OpenSSL genrsa-des3-out hupohost.key 4096

Then he will ask you to enter the password for this key file. Input is not recommended. Because in the future to be used for nginx. Every time reload Nginx configuration, you need to verify this Pam password.

The password must be entered at build time. You can type it and then delete it.

The code is as follows Copy Code
MV Ssl.key Xxx.key
OpenSSL rsa-in xxx.key-out Hupohost.key
RM-RM Xxx.key


Then generate the certificate request file based on this key file

The code is as follows Copy Code

OpenSSL Req-new-key hupohost.key-out HUPOHOST.CSR

The above command generation to fill a lot of things to read and write it (you can casually, after all, this is the certificate of their own generation)

Finally, the CRT certificate file is generated based on these 2 files

The code is as follows Copy Code

OpenSSL x509-req-days 3650-in hupohost.csr-signkey hupohost.key-out hupohost.crt

Here 3650 is the certificate validity period recommendation 3650 haha. This is random. The last file to use is key and CRT files.

If you need to use a PFX you can use the following command to generate

The code is as follows Copy Code
OpenSSL pkcs12-export-inkey hupohost.key-in hupohost.crt-out hupohost.pfx


Add the following configuration to the server node where you need to use the Nginx configuration file for the certificate

The code is as follows Copy Code

SSL on;
SSL_CERTIFICATE/HOME/HUPOHOST.CRT;
Ssl_certificate_key/home/hupohost.key;
Ssl_session_timeout 5m;
Ssl_protocols SSLv2 SSLv3 TLSv1;
Ssl_ciphers all:! Adh:! Export56:rc4+rsa:+high:+medium:+low:+sslv2:+exp;
Ssl_prefer_server_ciphers on;

and restart the Nginx.

Most importantly, access is HTTPS.

The code is as follows Copy Code
server{
Listen 443;
SSL on;
SSL_CERTIFICATE/USR/LOCAL/NGINX/CONF/VHOST/SSL/HUPOHOST.CRT;
Ssl_certificate_key/usr/local/nginx/conf/vhost/ssl/hupohos.key;
}

Port must be 443 ports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.