Nginx Configuration
1. Configure Nginx
Edit the Nginx configuration file, typically located at /etc/nginx/sites-available/default or /etc/nginx/nginx.conf:
1sudo vi /etc/nginx/sites-available/default
2. Add HTTPS Configuration
In the configuration file, find the server block and add or modify the following:
1server {
2 listen 80;
3 server_name your_domain.com www.your_domain.com;
4
5 # Redirect HTTP to HTTPS
6 return 301 https://$host$request_uri;
7}
8
9server {
10 listen 443 ssl;
11 server_name your_domain.com www.your_domain.com;
12
13 ssl_certificate /path/to/your_certificate.crt;
14 ssl_certificate_key /path/to/your_private.key;
15
16 # Other configurations...
17}
3. Test Nginx Configuration
After saving your changes, test the Nginx configuration for errors:
1sudo nginx -t
4. Reload Nginx
If the configuration is correct, reload Nginx to apply the changes:
1sudo systemctl reload nginx