Skip to content

Instantly share code, notes, and snippets.

@gmilby
Created November 10, 2013 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmilby/7400964 to your computer and use it in GitHub Desktop.
Save gmilby/7400964 to your computer and use it in GitHub Desktop.
How To Host Ghost with Nginx on DigitalOcean inShare Write an Article Introduction In April 2013, John O'Nolan, no newcomer to the field of blog-making, launched a Kickstarter for a new kind of blog called Ghost, which could radically simplify writing and maintaining a blog. Here, we'll walk through all of the steps to get Ghost set up and running on a DigitalOcean VPS. Prerequisites Before you get started, there are a few things that you should pull together Obtain a copy of Ghost This tutorial will assume you already have a copy of Ghost on your local computer. Since it's only available to Kickstarter backers right now, you should have been sent a link to the site where you can download it. Set up a VPS This tutorial will assume that you've already set up a VPS. We'll be using Ubuntu 12.04, but you should be fine with whatever you'd like. If you need help with this part, this tutorial will get you started. Point a domain at your VPS This tutorial will assume that you've already pointed a domain at your VPS. This tutorial should help you out with that part, if you're unsure of how to do that. Step 1: Install npm Before we get started, I highly recommend making sure your system is up-to-date. Start by SSHing into your VPS by running: ssh root@*your-server-ip* on your local machine, and running the following on your VPS: apt-get update apt-get upgrade Once that is complete, we need to get npm installed. Running the following commands will install some dependancies for Node, add its repository to apt-get, and then install nodejs. apt-get install python-software-properties python g++ make add-apt-repository ppa:chris-lea/node.js apt-get update apt-get install nodejs Note: You shouldn't need to run the commands with sudo because you're probably logged in as root, but if you're deviating from this tutorial and are logged in as another user, remember that you'll probably need sudo. Now, if you run npm at the command line, you should see some help information printed out. If that's all good, you're ready to install Ghost! Step 2: Install Ghost The next thing to do will be getting your copy of Ghost onto the remote server. Please note that this step is only necessary for now, while Ghost is in beta. Once it is available to the public, it will be installable through npm (and this tutorial will likely be updated to reflect that). You're welcome to download the file directly to your VPS or transfer it via FTP. I will show you how to use SCP to copy the folder from your host to the server. The following commands are to be run in your local terminal: cd /path/to/unzipped/ghost/folder scp -r ghost-0.3 root@*your-server-ip*:~/ This will copy all of the contents of the ghost-0.3 folder to the home folder of the root user on the server. Now, back on the remote server, move into the Ghost folder that you just uploaded and use npm to install Ghost. The commands will look something like this: cd ~/ghost-0.3 npm install --production Once this finishes, run the following to make sure that the install worked properly: npm start Your output should look something like the following: > ghost@0.3.0 start /root/ghost-0.3 > node index Ghost is running... Listening on 127.0.0.1:2368 Url configured as: http://my-ghost-blog.com If that is the case, congratulations! Ghost is up and running on your server. Stop the process with Control-C and move onto the next steps to complete the configuration. Step 3: Install and Configure nginx The next step is to install and configure nginx. Nginx (pronounced "engine-x") is "a free, open-source, high-performance HTTP server and reverse proxy". Basically, it will allow connections from the outside on port 80 to connect through to the port that Ghost is running on, so that people can see your blog. Intallation is simple: apt-get install nginx Configuration is only a little more challenging. Start off by cding to nginx's configuration files and removing the default file: cd /etc/nginx/ rm sites-enabled/default Now, make a new configuration file: cd sites-available touch ghost And paste in the following code, modifying it to adapt to your own configuration (the only thing you should need to change is the domain name): server { listen 0.0.0.0:80; server_name *your-domain-name*; access_log /var/log/nginx/*your-domain-name*.log; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:2368; proxy_redirect off; } } Finally, create a symlink from the file in sites-available to sites-enabled: cd .. ln -s sites-available/ghost sites-enabled/ghost This will listen for traffic incoming on port 80 and pass the requests along to Ghost, provided they are connecting to the domain that you provide. Start up the server again (use the code from the end of Step 2) and visit your domain. If you see Ghost, you're good to go! Step 4: Configure Upstart The last step is to make an Upstart task that will handle Ghost and make sure that, should your server get turned off for some reason, Ghost will get kicked back on. Start by making a new Upstart configuration file by doing the following: cd /etc/init nano ghost.conf And paste in the following configuration: # ghost # description "An Upstart task to make sure that my Ghost server is always running" # author "Your Name Here" start on startup script cd /root/ghost npm start end script This should ensure that Ghost gets started whenever your server does, and allow you to easily control Ghost using service ghost start, service ghost stop, and service ghost restart. Try this tutorial on an SSD cloud server. Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for $5/mo! Learn more. Comments dixonge typo under symlinks? 'sites-enabled-ghost' should be 'sites-enabled/ghost' right? Posted October 14th, 2013 13:28 Joonas Hi Dixonge, Thanks for catching that, we've corrected the article. Posted October 14th, 2013 14:21 joesell89 "Step the process..." I presume that should read "Stop the process..." Posted October 14th, 2013 19:19 daniel.fuerg I don't get it working... Perhaps here is a mistake? Don't understand where the error is... root@SocialThoughtsGhostly:/etc/nginx# cd/etc/nginx rm sites-enabled/default -bash: cd/etc/nginx: No such file or directory root@SocialThoughtsGhostly:/etc/nginx# cd /etc/nginx rm sites-enabled/default root@SocialThoughtsGhostly:/etc/nginx# cd sites-available touch ghost root@SocialThoughtsGhostly:/etc/nginx/sites-available# server { listen 0.0.0.0:80; server_name social-thoughts.de; access_log /var/log/nginx/social-thoughts.de.log; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:2368; proxy_redirect off; } } -bash: syntax error near unexpected token `}' Posted October 14th, 2013 19:42 Scott Robertson @daniel.fuerg you need to run "nano ghost" before pasting the contents of the config file. Posted October 16th, 2013 08:49 Kamal Nasser @joesell89: Thanks, I've updated the article. :] Posted October 16th, 2013 18:39 jeffmsmithdev There are issues with the Sqlite package if you head over to the Ghost forums. I am going to redo my droplet and try again. node v0.10.* is what is recommended. I don't want to use the Ghost Application image as I will use my droplet for other purposes. I guess I could split it in half..hmmm Posted October 18th, 2013 12:50 artenischloria I created ghost nginx configuration file and changed server_name to my ghost ip adress (i still don't have a domain name), but I launch ghost, i've got the wrong url (127.0.0.1:2368). I changed url setting in config.js file, just below 'production'. I've got the same issue. What did I missed? Posted October 19th, 2013 23:10 Kamal Nasser @artenischloria: i've got the wrong url (127.0.0.1:2368). Where do you see that? Posted October 20th, 2013 11:41 artenischloria @Kamal Nasser. Thanks helping a newbie! Here it is: root@ghost:/var/www/ghost# npm start > ghost@0.3.3 start /var/www/ghost > node index Ghost is running... Listening on 127.0.0.1:2368 Url configured as: http://my-ghost-blog.com Ctrl+C to shut down I changed config.js with my vps ip. I already tried ghost droplet, and it was fine. But I was curious to install ghost on ubuntu by myself. When I posted the first message, I had just installed ubuntu image. But now, i've got other apps on my vps. Posted October 20th, 2013 17:08 Kamal Nasser @artenischloria: Please pastebin config.js's contents. Make sure there is no sensitive data before you post it :] Posted October 20th, 2013 18:40 artenischloria http://pastebin.com/ebaWjgyL Maybe I forgot something :p Posted October 20th, 2013 19:14 artenischloria I thought my problem was in nginx configuration: server_name *your-domain-name*; access_log /var/log/nginx/*your-domain-name*.log; Do i have to write: server_name http://XXX.XXX.XXX.XXX access_log /var/log/nginx/XXX.XXX.XXX.XXX.log;??? Thanks. Posted October 20th, 2013 19:25 Kamal Nasser @artenischloria: Do i have to write: server_name http://XXX.XXX.XXX.XXX access_log /var/log/nginx/XXX.XXX.XXX.XXX.log;??? Yes (make sure you restart nginx afterwards). Also, try editing /etc/init/ghost.conf and replacing npm start with ENV=production npm start Then run restart ghost. Does that fix it? Posted October 21st, 2013 13:27 Antonio Andre Hello, can i install ghost platform to my subdomain? How? Thank you :) Posted October 24th, 2013 14:38 artenischloria @Kamal Nasser Thanks for your help Kamal, but I don't manage to run ghost with this tutorial. Perhaps I did something wrong before trying it. Now I've got problems with node.js too. So I'll handle it by myself or I'll retry with a new droplet. Thanks you very much! Posted October 24th, 2013 14:47 Kamal Nasser @Antonio: Do you want to install it on an existing droplet or a new separate droplet? If the former, do you have Apache or nginx installed on your droplet? Posted October 24th, 2013 18:16 Kamal Nasser @artenischloria: Let me know how it goes :] Posted October 24th, 2013 18:17 emiller42 doesn't this setup run Ghost as root? Isn't that a potential security issue? Posted October 27th, 2013 04:14 GEORGE LIU Added your above guide to compiled list of Ghost install guides http://ghost.centminmod.com/how-to-install-ghost-blogging-platform/ :) Posted October 27th, 2013 11:00 emiller42 Here is an init.d script to run Ghost under a service account. In my case, I have a 'ghost' user, and Ghost is installed at /home/ghost/ghost https://gist.github.com/emiller42/7191554 Posted October 28th, 2013 04:46 Daniel Barth I've followed this tutorial through the end of step 3 however when I visit my domain it only shows the "Index of" page with files and directories. Any thoughts as to what I could've done wrong? Posted October 29th, 2013 04:16 Kamal Nasser @Daniel: Do you have apache installed on your droplet? Posted October 29th, 2013 18:06 Daniel Barth @Kamal When running "apache2 -v" it shows I have version 2.2.22 installed. Posted October 30th, 2013 01:44 Kamal Nasser @Daniel: Are you serving any websites with apache? If not, I suggest you uninstall it and use nginx. Otherwise, you can either port your apache virtualhosts to nginx or hosting Ghost on a separate droplet. Posted October 30th, 2013 19:20 Daniel Barth @Kamal How can I port my virtual hosts? Posted October 30th, 2013 19:43 Kamal Nasser @Daniel: You will have to understand how nginx's virtualhosts work and write them manually based on what the Apache ones do. What kind of apps are you running on apache? Posted October 30th, 2013 19:58 Balaji Srinivasan Hi i tried all the steps. But when i start npm an visit the url i am getting "Hello! It is working!". In terminal i am getting below error when i restart the npm npm ERR! Error: ENOENT, open '/root/package.json' npm ERR! If you need help, you may report this log at: npm ERR! npm ERR! or email it to: npm ERR! npm ERR! System Linux 3.2.0-24-virtual npm ERR! command "/usr/bin/node" "/usr/bin/npm" "start" npm ERR! cwd /root npm ERR! node -v v0.10.21 npm ERR! npm -v 1.3.11 npm ERR! path /root/package.json npm ERR! code ENOENT npm ERR! errno 34 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /root/npm-debug.log npm ERR! not ok code 0 Posted November 1st, 2013 20:25 Kamal Nasser @Balaji: Make sure you cd into the directory that contains ghost: cd /root/ghost-0.3 Posted November 2nd, 2013 11:24 javier Thanks very much, I have my Ghost blog running in Digital Ocean. Muchas Gracias. Ya tengo mi Ghost en Digital Ocean. Posted November 7th, 2013 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment