To set up a redirection from HTTP to HTTPS on your WordPress site using Nginx, follow these organized steps:
- Access Nginx Configuration File: Open the Nginx configuration file for your site, typically located at
/etc/nginx/sites-enabled/000-default.conf. - Modify Server Block Listen Directive:
- Locate the server block that defines your site.
- Change
listen 80tolisten 443 ssl;to ensure Nginx listens on HTTPS port.
- Add Redirect for HTTP Requests:
- This redirects any request to HTTPS while preserving the domain and path.
- Handle Multiple Domains: If you have multiple domains pointing to your site, ensure each server block includes this redirect or use a wildcard approach if applicable.
- Test Configuration:
- After making changes, test using
curlcommands or check access logs. - Clear Nginx cache if necessary before testing to avoid issues.
- After making changes, test using
- Inform Users: Optionally, notify users about the redirection for their awareness.
- Address Mixed Content Warnings: Implement measures like setting a Content Security Policy to resolve mixed content warnings after ensuring HTTPS redirects are in place.
Within the same server block, add a location block to handle all incoming requests:
location / {
redirect "https://$host$request_uri";
}
