How to enable HTTPS?
HTTPS (Hyper Text Transfer Protocol Secure) is the protocol used to transfer data in an encrypted format. It is used to secure the sensitive data like bank details, credentials, etc. from being exposed to the hackers. It generally uses the SSL certificate to secure the connection between the two end-points.
To enable HTTPS,
Prerequisite:
- Key and CRT file for SSL configuration
- Genuine SSL Certificate
HTTP to HTTPs Redirection
Add the below code in the fmt_nginx.conf file. You can find the file from the below path location.
/etc/nginx/conf.d/fmt_nginx.conf
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name localhost;
ssl on;
ssl_certificate /etc/ssl/certs/nginx.crt; <------ Add Client’s CRT file path
ssl_certificate_key /etc/ssl/private/nginx.key; <------ Add Client’s Key File Path
}
Only HTTPs Redirection
Add the below code in the fmt_nginx.conf file. You can find the file from the below path location.
/etc/nginx/conf.d/fmt_nginx.conf
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl on;
ssl_certificate /etc/ssl/certs/nginx.crt; <------ Add Client’s CRT file path
ssl_certificate_key /etc/ssl/private/nginx.key; <--- Add Client’s Key File Path
}
Once the configuration is added, verify it using the below command:
nginx -t
If the syntax is proper, restart the nginx service using the below command:
systemctl restart nginx
The SSL certificate is now added to the Nginx server.