keepcalculator

06 Numbers and Powers

WordPress HTTPS on CentOS with Nginx Guide

Card No. 06·71261 · Updated · Standard formula, shown below

This guide walks you through securing a WordPress site with HTTPS on CentOS using Nginx as the web server. You will install Let’s Encrypt certificates, configure Nginx to use them, and update WordPress settings so all traffic is encrypted. By the end, your site will load with a padlock icon and rank better in search results.

What You’ll Need

  • A CentOS server (7 or 8) with Nginx already installed and serving WordPress.
  • Root or sudo access to the server.
  • A domain name pointing to your server’s public IP (HTTPS won’t work with a bare IP).
  • Port 80 and 443 open in your firewall.

Step-by-Step

  1. Update your system – Run sudo yum update -y (or sudo dnf update on CentOS 8) to ensure all packages are current.
  2. Install Certbot and the Nginx plugin – Certbot is the official Let’s Encrypt client. Install it with sudo yum install certbot python3-certbot-nginx. On CentOS 8, use sudo dnf install certbot python3-certbot-nginx.
  3. Verify Nginx configuration – Make sure your WordPress site is working over HTTP. Check your Nginx server block (usually in /etc/nginx/conf.d/) and confirm the server_name directive matches your domain.
  4. Run Certbot to obtain a certificate – Execute sudo certbot --nginx -d example.com -d www.example.com (replace with your actual domain). Certbot will ask for an email address and agree to the terms. It will then automatically modify your Nginx config to enable HTTPS.
  5. Test the renewal – Let’s Encrypt certificates expire every 90 days. Certbot installs a timer automatically. Test it with sudo certbot renew --dry-run. If it succeeds, your certificates will renew automatically.
  6. Update WordPress site URL – Log into your WordPress admin dashboard. Go to Settings → General and change both WordPress Address (URL) and Site Address (URL) to https://example.com (and https://www.example.com if you use www). Save changes.
  7. Force HTTPS in WordPress (optional but recommended) – Add the following to your wp-config.php file (before the “That’s all” line):
    define('FORCE_SSL_ADMIN', true);
    This ensures admin pages are always secure.
  8. Redirect HTTP to HTTPS – Certbot usually adds a redirect. If not, edit your Nginx server block for port 80 and add:
    return 301 https://$host$request_uri;
    Then reload Nginx with sudo systemctl reload nginx.
  9. Update any hardcoded links – In your WordPress database, search for http://example.com and replace with https://example.com. You can use a plugin like “Better Search Replace” or run SQL commands via phpMyAdmin. This prevents mixed content warnings.
  10. Check your site – Visit https://example.com and verify the padlock appears. Use an online SSL checker to confirm the certificate is valid.

Common Mistakes

  • Forgetting to update the WordPress URL – If you leave the site URL as HTTP, WordPress will keep redirecting to HTTP, causing a redirect loop.
  • Mixed content – If your theme or plugins load images, CSS, or scripts over HTTP, the padlock will not show. Use a plugin like “Really Simple SSL” to automatically fix mixed content.
  • Not opening port 443 – If your firewall blocks HTTPS, the site won’t load. Allow it with sudo firewall-cmd --add-service=https --permanent and reload.
  • Using a bare IP – Let’s Encrypt does not issue certificates for IP addresses. You must use a domain.

Tips

  • Use a staging site – If possible, test the HTTPS setup on a staging copy before applying to your live site.
  • Enable HTTP/2 – HTTP/2 requires HTTPS and speeds up your site. In your Nginx server block, add listen 443 ssl http2; (or just http2 on; for Nginx 1.25+).
  • Set up a redirect for www vs non-www – Choose one version and redirect the other to avoid duplicate content. Certbot can help with this if you specify both domains.
  • Backup before changes – Always back up your Nginx config and WordPress database before making significant changes.

Troubleshooting

  • Redirect loop – This usually means your WordPress URL is still HTTP. Check wp_options table for siteurl and home values. If you can’t access admin, temporarily add define('WP_HOME','https://example.com'); and define('WP_SITEURL','https://example.com'); to wp-config.php.
  • Certificate not renewing – Run sudo certbot renew --dry-run to see errors. Common issues include port 80 being blocked (Let’s Encrypt uses HTTP for validation) or the domain not resolving to the server.
  • “Your connection is not private” – This usually means the certificate is invalid or expired. Check the certificate with sudo certbot certificates. If it’s expired, run sudo certbot renew --force-renewal.
  • Mixed content warnings – Use your browser’s developer tools (F12) to find insecure requests. Replace http:// with https:// in your theme files or use a plugin to force HTTPS.
  • Nginx fails to start – After editing config, test with sudo nginx -t. If it fails, check for syntax errors like missing semicolons or mismatched braces.

Frequently Asked Questions

Do I need a dedicated IP address for HTTPS?

No. With SNI (Server Name Indication), you can host multiple HTTPS sites on one IP. Let’s Encrypt works fine with shared IPs.

Can I use a self-signed certificate instead of Let’s Encrypt?

Yes, but browsers will show a warning. Let’s Encrypt is free and trusted, so it’s the better choice for public sites.

Will HTTPS affect my WordPress SEO?

Yes, positively. Google uses HTTPS as a ranking signal, and it improves user trust.

How do I redirect all HTTP traffic to HTTPS?

Certbot usually does this automatically. If not, add a return 301 https://$host$request_uri; in the port 80 server block.

What if I have multiple domains pointing to the same WordPress site?

You need a certificate that covers all domains. Use the -d flag multiple times, e.g., certbot --nginx -d example.com -d example.net. Then configure WordPress to use one canonical domain.

Can I install Let’s Encrypt on CentOS 6?

It’s not recommended because CentOS 6 is end-of-life and lacks Python 3. Upgrade to CentOS 7 or 8.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →