Get the App
SLTechnology News&Howtos  ›  Servers  › 

CVM: nginx uses ssl module to configure HTTPS support

Shulou Source: shulou.com Published: 2022-06-02 17:41:08 10月11日 Update

The ssl module is not installed by default, and if you want to use it, you need to specify the-with-http_ssl_module parameter at compile time. The installation module depends on the OpenSSL library and some reference files, which are usually not in the same package. Usually this file name is similar to libssl-dev.

Generate a certificate

You can generate a simple certificate by following these steps:

First, go to the directory where you want to create the certificate and private key, for example:

$cd / usr/local/nginx/conf

Create the server private key, and the command will ask you to enter a password:

$openssl genrsa-des3-out server.key 1024

Create the certificate to sign the request (CSR):

$openssl req-new-key server.key-out server.csr

Remove the necessary passwords when loading Nginx supported by SSL and using the private key above:

$cp server.key server.key.org

$openssl rsa-in server.key.org-out server.key

Configure nginx

Finally, mark the certificate using the above private key and CSR:

$openssl x509-req-days 365-in server.csr-signkey server.key-out server.crt

Modify the Nginx configuration file to contain the newly marked certificate and private key:

Server {

Server_name YOUR_DOMAINNAME_HERE;listen 443ssl on;ssl_certificate / usr/local/nginx/conf/server.crt;ssl_certificate_key / usr/local/nginx/conf/server.key

}

Restart nginx.

This allows access in the following ways:

Https://YOUR_DOMAINNAME_HERE

You can also add the following code to redirect port 80 to 443

Server {

Listen 80

Server_name ww.centos.bz

Rewrite ^ (. *) https://$server_name$1 permanent

}

Tags: Certificate file module configuration password can be passed tag generate server support service code parameter command situation file name method step directory software Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info Docker Huawei Microsoft