> ## Content Index
> Fetch the complete content index at: https://blog.esadax.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Redirecting HTTP to HTTPS with Nginx Configuration
- URL: https://blog.esadax.com/en/redirecting-http-to-https-with-nginx-configuration/
- Published: 2026-11-15T04:16:18.000Z
- Updated: 2026-11-15T04:16:18.000Z
- Author: Esadax 
- Tags: #tr-faq-06-ssl-installing-an-ssl-certificate-on-nginx, #en, #mdx-imported, FAQ

To redirect your website from HTTP to HTTPS using Nginx, follow these steps:

1. **Locate the Configuration File**:
  - For RHEL-based systems: `/etc/nginx/conf.d/default.conf`
  - For Debian-based systems: `/etc/nginx/sites-enabled/default`
2. **Identify the Server Block for Port 80**:
  - Use commands like `sudo nginx -T | grep -iw "configuration file"` or look for `include` directives to find the relevant configuration file.
3. **Add the Redirect Directive**:
  - Open the identified server block in your preferred text editor.
  - Ensure it is within the `server` block listening on port 80.
  - Add the line `return 301 https://$server_name$request_uri;` as the last directive in the block.
4. **Restart Nginx**:
  - After making changes, restart Nginx to apply the new configuration.
5. **Test the Redirect**:
  - Visit your site over HTTP to ensure it redirects correctly to HTTPS.

**Example Configuration**:

```nginx
listen 80;
server_name your_domain.com www.your_domain.com;
return 301 https://$server_name$request_uri;

```