Configure Digital Ocean VPS to host multiple Ghost blogs

Configure Digital Ocean VPS to host multiple Ghost blogs

Edit

This tutorial is was written before Ghost 1.x was released. With Ghost 1.x some of the steps became obsolete. We will update this article with specific steps to install multiple Ghost blogs on a single VPS.


Original Post

Follow these steps for < Ghost 1.x. This tutorial assumes you have at least two domain names, which are pointing at your digitalocean droplet where you already have Ghost installed.

So, let’s begin. Fist we need to stop both nginx and ghost to avoid problems:

service ghost stop
service nginx stop

Now, we need to modify the nginx configuration. We need to define different paths in order to be able to handle requests separately. So, navigate to:

cd /etc/nginx/sites-enabled

Now, rename the ghost configuration file according to our first domain and then copy that to our second domain configuration file. We will change it later.

mv ghost myfirstdomain.conf
cp myfirstdomain.conf myseconddomain.conf

Then we have to modify our configuration files. So open the first one using nano or vim:

nano myfirstdomain.conf

and change the server_name to myfirstdomain.com

server_name myfirstdomain.com 

in the server section we have the following code:

server {  
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    ...
}

We have to edit our second configuration file, the server_name will be myseconddomain.com and in addition we have to change the proxy_pass value, in order to be able to split the traffic between the two sites. It can be any port number that is not used by another process, so let’s say 2378.

server_name myseconddomain.com
proxy_pass http://localhost:2777

We also need to change the server section of our second .conf file. It cannot be default server as well, so it will look like this:

server {  
    listen 80;
    listen [::]:80;
    ...
}

Then save the file and restart nginx.

service nginx restart

Now, we need to change the Ghost configuration. Go to the web root directory and create a directory for each Ghost blog:

cd /var/www
mkdir myfirstdomain.com
mkdir myseconddomain.com

We need to copy the Ghost directory into our new folders:

cp -r ghost myfirstdomain.com
mv ghost myseconddomain.com

Now, we can open our first Ghost configuration file and change the production url.

nano /var/www/myfirstdomain.com/ghost/config.js

Change the value of url in the production section to the first domain’s url:

production: {
    url: 'http://myfirstdomain.com'
    ...
}

Save and close the file and then we have to do the same thing for the second Ghost site.

nano /var/www/myseconddomain.com/ghost/config.js

Of course, in the production section the value of the url will be corresponding to our second domain and in addition you have to scroll down to the server section and change the port:’2378’

production: {
    url: 'http://myseconddomain.com'
    port: '2378'
    ...
}

To be able to easily manage our Ghost blogs separately we have to create Upstart Scripts, which will allow us to start, stop, restart and check status of each ghost site. So first we have to delete the old System V Script

rm /etc/init.d/ghost

Now we can create the new configuration for our sites. Go to the init directory and create the first configuration file:

cd /etc/init
nano ghost-myfirstdomain.conf

and paste the following code:

# ghost-myfirstdomain

start on startup

script
    cd /var/www/myfirstdomain.com/ghost
    npm start --production
end script

save and close this file, then copy it to the second site’s configuration file, and change accordingly

cp ghost-myfirstdomain.conf ghost-myseconddomain.conf

In our case the second configuration file will look like this:

# ghost-myseconddomain

start on startup

script
    cd /var/www/myseconddomain.com/ghost
    npm start --production
end script

The last step is to start the Ghost blogs by running:

service ghost-myfirstdomain start
service ghost-myseconddomain start

If you visit each of your domains, you should see the Ghost blog landing page.