July 11, 2022

How To Redirect to HTTPS for WordPress with NGINX and SSL Certified by Bitnami and Automattic

After deploying the SSL certificate to the new WordPress virtual machine I still had to figure out how to redirect HTTP traffic to the secure HTTPS endpoint. Buried in the Bitnami support forums are the steps to easily update NGINX.

First, open the NGINX server block specific for WordPress. (Yes, I use pico)

sudo pico /opt/bitnami/nginx/conf/server_blocks/wordpress-server-block.conf

Once the conf file is open, look for the line "server_name _;" and right below that enter the one line below. The line will instruct NGINX to redirect port 80 (HTTP) traffic to HTTPS.

return 301 https://$host$request_uri;

Save the conf file. Use the next two commands to test config and restart NGINX.

sudo nginx -t
sudo /opt/bitnami/ctlscript.sh restart nginx

Visit your WordPress site at http://YOURDOMAIN and it will automatically forward to https://YOURDOMAIN.

FILED UNDER:  Google Cloud , WordPress