Nginx + WordPress

4. Configure Nginx Server Blocks

In Apache, you can host multiple websites in a server with a single IP address using virtual hosts. In Nginx, it is called server blocks. Each website needs its own server block so that the server would know from which directory would it get the correct website files to display in the visitors’ web browser. It also contains the rules to process on how to redirect or restrict the visitors depending on their requests.

First thing, let us isolate each of the websites from one another by creating a separate php-fpm pool being owned by separate user/s and group/s.

 

Create a separate php-fpm config file for each website that would be hosted in the server.

Note: You should add/edit the configurations and values in this file depending on what your website needs and your server resource.

 

Create the directory to hold the website files for each of your domain. For now, let’s create one directory first. We will have this directory owned by the new user/group we created in the previous step.

 

Edit the new Nginx server block config we just created to point it to the newly created directory.

 

Enable the server block by creating a symbolic link in the sites-enabled directory.

 

Edit the main Nginx configuration file.

 

Restart the webserver afterwards.

 

5. Install Free SSL Using Let’s Encrypt

Let’s Encrypt is a Certificate Authority (CA) which provides trusted TLS/SSL certificate so you could enable encrypted HTTPS on your webserver. The only price you have to pay is to renew it every 90 days.

We need to install git and bc and clone the Let’s Encrypt repository.

 

After cloning the Let’s Encrypt repository, let’s proceed in getting our SSL certificate.

 

After getting the SSL certificate, we need to edit our site configuration file /etc/nginx/sites-available/example.com to use it.

 

6. Install WordPress

Finally, the last step we would do is to install the one of the most popular blogging platforms, WordPress. You would easily put your website up without worrying much about coding. Themes and plugins are widely available for you to download and use in your WordPress.

Let us first prepare a database which would be use by our WordPress to store all data it would use.

Note: Provide the MySQL root password if you set any during MySQL/MariaDB installation

 

Let’s now download WordPress and some packages that it would be use.

 

Next, we would configure our WordPress configuration file wp-config.php and edit it to use the new database we just created.

 

After editing the WP configuration file, we can now move it to our website root directory so we can access it from the internet.

 

Before we proceed with the final process in installing WordPress, let us adjust our Nginx configuration file /etc/nginx/sites-available/example.com to instruct how it would handle the request.

 

Finally, complete the installation by accessing WordPress through your web browser.

http://example.com/

 

 

Leave a Reply