Debian 12 bookworm
Sponsored Link

Nginx : SSL/TLS Setting2023/07/04

 
Enable SSL/TLS setting to use secure encrypted connection.
[1]
[2] Configure Nginx. For example, enable SSL/TLS on default site.
root@www:~#
vi /etc/nginx/sites-available/default
# add to the end
# replace servername and path of certificates to your own one

server {
       listen       443 ssl http2 default_server;
       listen       [::]:443 ssl http2 default_server;
       server_name  www.srv.world;
       root         /var/www/html;
       index index.html index.htm index.nginx-debian.html;

       ssl_certificate "/etc/letsencrypt/live/www.srv.world/fullchain.pem";
       ssl_certificate_key "/etc/letsencrypt/live/www.srv.world/privkey.pem";
       ssl_session_cache shared:SSL:1m;
       ssl_session_timeout  10m;

       location / {
              try_files $uri $uri/ =404;
       }
}

root@www:~#
systemctl reload nginx

[3] If you'd like to set HTTP connection to redirect to HTTPS (Always on SSL/TLS), configure like follows.
root@www:~#
vi /etc/nginx/sites-available/default
# add into the section of listening 80 port

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        return 301 https://$host$request_uri;

root@www:~#
systemctl reload nginx

[4] Verify to access to the test page from a client computer with Web browser via HTTPS. If you set Always On SSL/TLS, access with HTTP to verify the connection is redirected to HTTPS normally, too.
Matched Content