GCP

Bitnami WordPress NGINX SSL certificate Installation

Enable HTTPS secure server on your WordPress with NGINX and SSL Certified by Bitnami and Automattic stack image. This will make website more secure, enhance user experience, Boost SEO and much more.

Install SSL certificate for your Bitnami nginx WordPress stack image.

You can install the SSL certificate for your Bitnami NGINX WordPress stack for free using Let’s Encrypt. For this, first of all, you’ve to set the domain name for your WordPress website.

bitnami-wordpress-nginx-ssl-certificate-install
bitnami-wordpress-nginx-ssl-certificate-install

Now open SSL terminal of the virtual machine, if you don’t know how to open the terminal learn here.

Generate SSL for your Domain

To generate SSL (Secure Sockets Layer) first you’ve to get in with root permission.

Stop NGINX to generate SSL
Stop NGINX to generate SSL

Now stop nginx server of your WordPress application. To exclude this operation paste the following command one by one.

sudo -i
sudo /opt/bitnami/ctlscript.sh stop nginx
Generate SSL Certificate Bitnami nginx
Generate SSL Certificate Bitnami nginx

Now generate a renewable SSL certificate for your website by executing the following

sudo /opt/bitnami/letsencrypt/lego --tls --email="youremail@gmail.com " --domains="iasrank.in" --domains="www.iasrank.in" --path="/opt/bitnami/letsencrypt" run

In the above command please replace email and domain name with your own values.

SSL certificate will be successfully generated for your blog, now you’ve to configure your blog to serve using this SSL certificate.

Start NGINX server of WordPress.

Start Bitnami NGINX
Start Bitnami NGINX

Your Nginx server is turned off during the certificate generation. To turn it on executing the following command for bitnami NGINX.

sudo /opt/bitnami/ctlscript.sh start nginx

Configure Bitnami WordPress stack for SSL certificate

Its time to configure your SSL certificate with the root of the WordPress application. This will enable nginx to find the certificate and redirect your domain to one prefered URL.

bitnami-config-nginx redirect 301
Bitnami configuration

Now we’ve to move all non-secure or HTTP traffic to the secure SSL or HTTPS server to do this will add the following line to server 80:

return 301 https://iasrank.in$request_uri;

change iasrank.in with www or non-www version of your website. Now we point all traffic to one naked domain(in our case). And provide a path for SSL certificate. Edit server 443, add the following lines

if ($host = 'www.iasrank.in') {
return 301 https://iasrank.in$request_uri;
}
ssl_certificate      "/opt/bitnami/letsencrypt/certificates/iasrank.in.crt";
ssl_certificate_key  "/opt/bitnami/letsencrypt/certificates/iasrank.in.key";

the above settings will redirect your traffic to https://iasrank.in, or we can say a naked domain. To move all traffic to https://www.iasrank.in paste the code provided below instead of the above.

if ($host = 'iasrank.in') {
return 301 https://www.iasrank.in$request_uri;
}
ssl_certificate      "/opt/bitnami/letsencrypt/certificates/iasrank.in.crt";
ssl_certificate_key  "/opt/bitnami/letsencrypt/certificates/iasrank.in.key";

And now comment out previous SSL certificate files by adding #(hash) as displayed above. Now modified code will look like this(for old SSL)

#       ssl_certificate      server.crt;
#       ssl_certificate_key  server.key;

All done, save the file using ctrl+X, then Y and then press enter. Your changes will be save.

Configure WordPress for SSL certificate.

You can configure WordPress by editing wp-config.php file, to do that execute the code provided below.

Edit wp-config.php NGINX WordPress bitnami
Edit wp-config.php NGINX WordPress bitnami
nano /opt/bitnami/apps/wordpress/htdocs/wp-config.php

This will open wp-config.php file to SSH editor.

wp config edit ngix ssl configure

Now replace http to https for your wordpress domain

define('WP_SITEURL', 'http://iasrank.in');
define('WP_HOME', 'http://iasrank.in');

replace with 

define('WP_SITEURL', 'https://iasrank.in');
define('WP_HOME', 'https://iasrank.in');

Now press ctrl+X, then Y and Press Enter to save the changes.

Test and Restart Bitnami NGINX
Test and Restart Bitnami NGINX

Now in final step you’ve to test and restart NGINX. excute nginx -t to test NGINX and restart. If any error occur in nginx configuration please match the configuration as per result.

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

Now all done, your Bintami WordPress now run on HTTPS secure server with lets encrypt SSL certificate. If you’ve any question regarding this you can ask in comment section below.

Ashok Kumar

Love Coding, Love Blogging what else to explain :).

Related Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button