To redirect your website from HTTP to HTTPS using Nginx, follow these steps:
Locate the Configuration File:
/etc/nginx/conf.d/default.conf/etc/nginx/sites-enabled/defaultIdentify the Server Block for Port 80:
sudo nginx -T | grep -iw "configuration file" or look for include directives to find the relevant configuration file.Add the Redirect Directive:
server block listening on port 80.return 301 https://$server_name$request_uri; as the last directive in the block.Example Configuration:
listen 80;
server_name your_domain.com www.your_domain.com;
return 301 https://$server_name$request_uri;
Restart Nginx:
Test the Redirect: