Bobcares

WordPress subdomain on Nginx with SSL: How to setup?

by | May 23, 2023

Let us learn how to setup WordPress subdomain on Nginx with SSL with the support of our WordPress support services at Bobcares.

Why use Nginx with WordPress?

WordPress is a widely used self-hosted Content Management System (CMS) for powering blogs and general-purpose websites.

Building a quick and dependable WordPress website necessitates the use of a trustworthy web server, such as Nginx, to provide all essential files requested by website visitors on a given domain.

This article demonstrates how to install WordPress on a subdomain and configure it to operate properly with the underlying architecture using Nginx as the web server and MySQL or MariaDB as the database server.

Requirements to setup the WordPress subdomain on Nginx with SSL

Before beginning the setup porcess we have to ensure the following:

  • Install a fresh Ubuntu 20.04 server with a LEMP stack, or deploy a Vultr One-Click LEMP server.
  • Make a subdomain and point it to the server.
  • Use sudo to connect to the server as a non-root user.

Setup the WordPress Database to setup subdomain on Nginx with SSL

Follow the steps given below as initial setup process:

  1. Firstly we have to access the MySQL database server by typing in the following command line:

    $ mysql -u root -p

  2. After that we ahve to create a new database by using the following command line:

    mysql CREATE DATABASE wp;

  3. Make a new database user with a strong password.

    mysql CREATE USER `wpuser`@`localhost` IDENTIFIED BY ‘Strong-Password’;

  4. Give the user complete access to the WordPress database.

    mysql GRANT ALL PRIVILEGES ON wp.* TO 'wpuser’@’localhost';

  5. After that, we have to refresh the MySQL privileges:

    mysql> FLUSH PRIVILEGES

  6. Finally, we have to exit the MySQL console:

    mysql> EXIT

This is the first step to setup the WordPress subdomain on Nginx with SSL.

Install WordPress

Follow the steps given below to setup the WordPress:

  1. Make a new files directory in WordPress:

    $ sudo mkdir /var/www/wp.example.com

  2. Get the most recent WordPress release file.

    $ wget http://wordpress.org/latest.tar.gz

  3. Files should be extracted from the archive.

    $ tar -xzf latest.tar.gz

  4. Move the files in the WordPress directory.

    $ sudo mv wordpress/* /var/www/wp.example.com

  5. Give Nginx read and write access to the directory.

    $ sudo chown -R www-data:www-data /var/www/wp.example.com

Configure Nginx

Now we have to configure the Nginx to set up the WordPress subdomain on Nginx with SSL. Follow the steps given below for setting this up:

  1. Firstly, in the /etc/nginx/sites-available directory, create a new Nginx Server Block.

    $ sudo touch /etc/nginx/sites-available/wp.example.com.conf

  2. After that, edit the server block file using any text editor.

    $ sudo nano /etc/nginx/sites-available/wp.example.com.conf

  3. Copy and paste the configuration lines below into the file.



    After that save and close the file after the configuration process.

  4. FastCGI Caching and PHP settings for the WordPress website are included in the configuration file.
  5. Check for configuration issues in Nginx.

    $ sudo nginx -t

  6. Link the Nginx server block to the /etc/nginx/sites-enabled directory to activate it.

    $ sudo ln -s /etc/nginx/sites-available/wp.example.com.conf   /etc/nginx/sites-enabled/wp.example.com.conf

  7. To make changes take effect, restart Nginx.

    $ sudo systemctl nginx restart

  8. Start PHP-FPM to serve PHP files from WordPress.

    $ sudo systemctl php7.4-fpm start

Now we have setup the Nginx to set up the WordPress subdomain on Nginx with SSL.

Security setup

Follow the steps given below to set up the security settings:

Allow HTTP and HTTPS ports to pass past the firewall.

On Debian-based systems with UFW:

For this type in the following command line:

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

FirewallD on RHEL-based systems:

Type in the following command line:

$ sudo firewall-cmd --permanent --zone=public --add-service=http.

$ sudo firewall-cmd --permanent --zone=public --add-service=https.

Install Certbot to provide HTTPS security to the WordPress site:

On Debian systems:

Type in the following lines:

$ sudo apt install certbot python3-certbot-nginx

On RHEL systems:

Use the folllowing line:

$ sudo yum install certbot python3-certbot-nginx

Certbot may be used to obtain a free Let’s Encrypt SSL Certificate:

Use the following xcommand line:

$ sudo certbot -d wp.example.com -d www.wp.example.com

Change the server block file in Nginx:

Use the following command line foir edititng:

$ sudo nano /etc/nginx/sites-available/wp.example.com.conf

In the server section, add the following lines to redirect all HTTP queries to HTTPS and to limit access to important website files such as.php and.htaccess.

Configure WordPress

This is the final step to set up the WordPress subdomain on Nginx with SSL.

Launch a new web browser session on the local machine and navigate to the specified subdomain.

Follow the steps given below to set this up:

    1. To begin the WordPress installation process, click Get Started.
    2. Enter the previously prepared Database information.
    3. Enter the title of the WordPress website and create a new administrator account.

Complete the setup and log in to the WordPress website.

  1. Navigate to Plugins in the WordPress administrator dashboard and select Add New Plugin.
  2. Enter the words Nginx Helper in the plugin search area, then download and install it on the WordPress website.
  3. To fine-tune your WordPress website with Nginx, navigate to the WordPress Settings drop-down and choose the Nginx Helper plugin.
  4. At the very least, activate Cache Purge to automatically clean FastCGI cache whenever new modifications are made to the website.

This step will conclude the set up of WordPress subdomain on Nginx with SSL.

[Need assistance with similar queries? We are here to help]

Conclusion

To sum up we have now seen how to set up the WordPress subdomain on Nginx with SSL with the support of our tech team.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.