Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CVM: nginx uses ssl module to configure HTTPS support

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report