In this recipe, we will learn how to enable HTTPs communication on the Nginx server.
Follow these steps to set HTTPs on Nginx:
Obtain a certificate and the related keys from a certification authority or create a self-signed certificate. To create a self-signed certificate, refer to the Securing web traffic with HTTPS recipe in this chapter.
Create a directory to hold all certificate and keys:
$ sudo mkdir -p /etc/nginx/ssl/example.com
Move the certificate and keys to the preceding directory. Choose any secure method, such as SCP, SFTP, or any other.
Create a virtual host entry or edit it if you already have one:
$ sudo nano /etc/nginx/sites-available/example.com
Match your virtual host configuration with the following:
server { listen 80; server_name example.com www.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name example...