How to Run Multiple WordPress Websites on One Nginx Server

Multiple WordPress websites on one server tutorial

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this tutorial, you’ll learn how to run multiple WordPress websites on one Nginx server. For example, if you have one hosting account with root access to an Nginx web server, you’ll be able to install as many WordPress websites as your heart desires.

Let’s get into the tutorial!

Note: I’ll assume you have root access to an Nginx web server. If not, get set up with on here.

1. Install and Configure WordPress and the Database

Let’s assume you already have one WordPress website up and running. If that’s not the case, that’s okay. Just repeat these steps as many times as you like.

The first thing we want to do is install another copy of WordPress. Please follow steps 5, 6, and 7 from this tutorial. For example, you’ll end up with two copies of WordPress installed at:

  1. WordPress Website #1 install location (original)
    /var/www/site1.com/wordpress
  2. WordPress Website #2 install location (new)
    /var/www/site2.com/wordpress

2. Configure Nginx for Multiple WordPress Websites

Next, you’ll want to make an Nginx configuration file for each of your WordPress websites in the /etc/nginx/sites-available directory.

  1. WordPress Website #1 site1.conf
    upstream site1-php-handler {
            server unix:/var/run/php/php7.2-fpm.sock;
    }
    
    server {
            listen 80;
    
            server_name site1.com www.site1.com;
            root /var/www/site1.com/wordpress;
    
            location / {
                    try_files $uri $uri/ /index.php?$args;
            }
    
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass site1-php-handler;
            }
    }
  2. WordPress Website #2 site2.conf
    upstream site2-php-handler {
            server unix:/var/run/php/php7.2-fpm.sock;
    }
    
    server {
            listen 80;
    
            server_name site2.com www.site2.com;
            root /var/www/site2.com/wordpress;
    
            location / {
                    try_files $uri $uri/ /index.php?$args;
            }
    
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass site2-php-handler;
            }
    }

Publish your websites by making a symlink from your Nginx configuration files to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/site1.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/site2.conf /etc/nginx/sites-enabled/

Finally, test your Nginx configuration changes and restart the web server.

nginx -t
systemctl restart nginx

3. Test it Out!

As long as you already have your DNS A records for site1.com and site2.com pointing to the IP address of your hosting plan or server, you’ll be able to visit these URLs and see that you have multiple WordPress websites being served from the same server.

Multiple sites on one server sharing the same IP address confirmed by ping

Any questions about hosting multiple websites on one IP address, let me know in the comments below. Also, here’s a video tutorial on the same topic if you prefer to watch that.

YouTube video

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony Teaches Tech headshot

With a strong background in computer science and enterprise web development, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

Leave a Reply

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