Secure your Nginx server with SSL/TLS to ensure encrypted and safe communication.
Before configuring SSL/TLS in Nginx, obtain your SSL certificates. For obtaining Let's Encrypt certificates, refer to the relevant documentation or guides.
Set up SSL/TLS on your Nginx server, for example, on the default site.
Edit or create a new SSL configuration file:
[root@www ~]# vi /etc/nginx/conf.d/ssl.conf
# Add the following SSL/TLS configuration:
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name www.emc.world;
root /usr/share/nginx/html;
ssl_certificate "/etc/letsencrypt/live/www.emc.world/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/www.emc.world/privkey.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
[root@www ~]# systemctl reload nginx
Automatically redirect all HTTP traffic to HTTPS for enhanced security.
[root@www ~]# vi /etc/nginx/nginx.conf
# Add the following inside the HTTP server block:
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$host$request_uri;
server_name www.emc.world;
root /usr/share/nginx/html;
}
[root@www ~]# systemctl reload nginx
Allow HTTPS traffic through the firewall:
[root@www ~]# firewall-cmd --add-service=https
success
[root@www ~]# firewall-cmd --runtime-to-permanent
success
Test the SSL/TLS configuration by accessing your website via a web browser using HTTPS. Ensure that HTTP requests are correctly redirected to HTTPS.