How to Install Ghost with Nginx on FreeBSD 10.2

Node.js is open source runtime environment for developing the server-side applications. Node.js application is written in javascript and can be run on the server that running Node.js runtime. It is cross-platform runtime, running on Linux, Windows, OSX, IBM AIX, including FreeBSD. Node.js was created by Ryan Dahl and other developer working at Joyent on 2009. It is designed to build scalable network applications.

Ghost is blogging platform coded in Node.js. It is open source publishing platform with beautifully designed, user-friendly, and free. It is allows you to easily publish your content on web, or create your portofolio website.

In this tutorial we will install a Ghost with Nginx as our web server on FreeBSD. We will install Node.js, Npm, nginx and sqlite3 on FreeBSD 10.2.

Step 1 - Install Node.js npm and Sqlite3

If you want to running ghost on your server, you must install node.js. In this section we will install node.js from the freebsd ports collection, please go to the ports directory "/usr/ports/www/node" and install by running command "make".

cd /usr/ports/www/node
make install clean

If you've done with node.js installation, please switch to the npm directory and install it. npm is Package manager for installs, publishes and manages node programs.

cd /usr/ports/www/npm/
make install clean

Next, please install sqlite3. By default ghost is use sqlite3 as the database system, but it is support too for mysql/mariadb and postgresql. We will use sqlite3 as the default database.

cd /usr/ports/databases/sqlite3/
make install clean

If all is installed, please check the version of node.js and npm :

node --version

npm --version

sqlite3 --version

node and npm version

Step 2 - Add Ghost User

We will install and running ghost under normal users called "ghost". please create new user with "adduser" command :

adduser ghost

Add user Ghost

Step 3 - Installing Ghost

We will install ghost under "/var/www/" directory, so let's create it and then go to the installation directory :

mkdir -p /var/www/
cd /var/www/

Download ghost latest version with wget command :

wget --no-check-certificate

Extract it to the directory called "ghost" :

unzip -d ghost

Next, change the owner as user "ghost", we will run and install it under that user.

chown -R ghost:ghost ghost/

If all is done, switch the user to "ghost" by typing command below :

su - ghost

Then go to the installation directory "/var/www/ghost/" :

cd /var/www/ghost/

And before install ghost, we need a sqlit3 modules for node js, install it with npm command :

setenv CXX c++ ; npm install sqlite3 --sqlite=/usr/local

Note : Run as "ghost" user, not root user.

And now we ready to install ghost, please install it with npm command :

npm install --production

Next, copy the configuration file "config.example.js" to "config.js", then edit it with nano editor :

cp config.example.js config.js
nano -c config.js

change on line 25 server block :

host: '',

Save and exit.

Now run ghost with command below :

npm start --production

And test by visiting the server ip and port 2368.

Ghost Installed

Ghost is installed on directory "/var/www/ghost", under user "ghost".

Step 4 - Run Ghost as FreeBSD Services

To run an application as service on freebsd, you need to add the script to the rc.d directory. we will create new service script for ghost in directory "/usr/local/etc/rc.d/".

Before we create the services script, we need to install a node.js module for running ghost as service, install forever module with npm command as sudo/root privileges :

npm install forever -g

Now please go to the rc.d directory and create new file called ghost there :

cd /usr/local/etc/rc.d/
nano -c ghost

Paste service script below :


# PROVIDE: ghost
# KEYWORD: shutdown

. /etc/rc.subr


load_rc_config ghost
: ${ghost_enable:="NO"}


ghost_start() {
sudo -u ghost sh -c "cd $ghost && NODE_ENV=production forever start -al $log index.js"

ghost_stop() {
sudo -u ghost sh -c "cd $ghost && NODE_ENV=production forever stop index.js"

ghost_status() {
sudo -u ghost sh -c "NODE_ENV=production forever list"

ghost_restart() {

run_rc_command "$1"

Save and exit.

Next, make ghost service script an executable :

chmod +x ghost

and create new directory and file for ghost log, and change the owner to ghost user :

mkdir -p /var/www/ghost/
touch /var/www/ghost/ghost.log
chown -R /var/www/ghost/

And the last if you want to run ghost service, you need to add ghost service to the boot time/startup application with sysrc command :

sysrc ghost_enable=yes

and start ghost with :

service ghost start

Other command :

service ghost stop
service ghost status
service ghost restart

Ghost service command

Step 5 - Install and Configure Nginx for Ghost

By default, ghost running standalone,, you can run it without Nginx, apache or IIS webserver. But in this tutorial we will install and configre nginx to work with Ghost.

Please install nginx from the freebsd repository with pkg command :

pkg install nginx

Next, go to nginx configuration directory and make new directory for virtualhost configuration.

cd /usr/local/etc/nginx/
mkdir virtualhost/

go to the virtualhost directory, make new file called ghost.conf with nano editor :

cd virtualhost/
nano -c ghost.conf

Paste virtualhost configuration below :

server {
listen 80;

#Your Domain

location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)$ {
access_log off;
expires 30d;
add_header Pragma public;
add_header Cache-Control "public, mustrevalidate, proxy-revalidate";

location / {
add_header X-XSS-Protection "1; mode=block";
add_header Cache-Control "public, max-age=0";
add_header Content-Security-Policy "script-src 'self' ; font-src 'self' ; connect-src 'self' ; block-all-mixed-content; reflected-xss block; referrer no-referrer";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;

location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

location ~ /\.ht {
deny all;


Save and exit.

To activate the virtualhost configuration, you need to include that file to the nginx.conf. please go to nginx configuration directory and edit nginx.conf file :

cd /usr/local/etc/nginx/
nano -c nginx.conf

Before the last line, include the virtualhost configuration directory :


include virtualhost/*.conf;


Save and exit.

Test nginx configuration with command "nginx -t", if there is no error, add nginx to the start up with command sysrc :

sysrc nginx_enable=yes

and start nginx :

service nginx start

Now test all nginx and virtualhost configuration. please open your browser and type the : successfully is running successfully.

If you want to check the nginx server, use "curl" command.

ghost and nginx test

Ghost is running with nginx.


Node.js is runtime environment created by Ryan Dahl for creating and developing scalable server-side applications. Ghost is open-source blogging platform coded in node.js, it is come with beautifully designed and easy to use for everyone. By default, the ghost is a web application that can stand on its own, does not require a webserver apache, nginx or IIS, but we can also integrate with a web server(In this tutorial use Nginx). Sqlite is default database used by ghost, but it supupport too for mysql/mariadb and postgresql. Ghost is fast and easy to use for you and configure.

Arul 3:00 am


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


  1. This tutorial doesn't work. The instructions under Step 3 do not work.

    I get errors after running:
    ghost@server:/var/www/ghost:$ setenv CXX c++ ; npm install sqlite3 --sqlite=/usr/local

    npm ERR! FreeBSD 10.2-RELEASE
    npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "sqlite3" "--sqlite=/usr/local"
    npm ERR! node v4.1.1
    npm ERR! npm v2.14.4
    npm ERR! path /var/www/ghost/node_modules/sqlite3
    npm ERR! code EACCES
    npm ERR! errno -13
    npm ERR! syscall rmdir

    npm ERR! Error: EACCES: permission denied, rmdir '/var/www/ghost/node_modules/sqlite3'
    npm ERR! at Error (native)
    npm ERR! { [Error: EACCES: permission denied, rmdir '/var/www/ghost/node_modules/sqlite3']
    npm ERR! errno: -13,
    npm ERR! code: 'EACCES',
    npm ERR! syscall: 'rmdir',
    npm ERR! path: '/var/www/ghost/node_modules/sqlite3' }
    npm ERR!
    npm ERR! Please try running this command again as root/Administrator.
    npm ERR! error rolling back Error: EACCES: permission denied, rmdir '/var/www/ghost/node_modules/sqlite3'
    npm ERR! error rolling back at Error (native)
    npm ERR! error rolling back { [Error: EACCES: permission denied, rmdir '/var/www/ghost/node_modules/sqlite3']
    npm ERR! error rolling back errno: -13,
    npm ERR! error rolling back code: 'EACCES',
    npm ERR! error rolling back syscall: 'rmdir',
    npm ERR! error rolling back path: '/var/www/ghost/node_modules/sqlite3' }

    npm ERR! Please include the following file with any support request:
    npm ERR! /var/www/ghost/npm-debug.log

    Sqllite is not installed in /usr/local so this seems like it is bound to fail. I ran the following and it still doesn't work.

    setenv CXX c++ ; npm install sqlite3 --sqlite=/usr/local/bin

    I still get the same errors. Has anyone gotten this tutorial to work?

    1. recently install ghost with this tutorial and with different version of node.js and this is work.

      dont forget for every step in this tutorials.
      dont forget to change the permission for ghost directory "/var/www/ghost" to ghost user.

  2. Hey, just a heads up that the ports tree has evolved since you wrote this article and these instructions no longer work.

    You will need to build the version of npm located in /usr/ports/www/node012/ in order to survive the `npm install sqlite` command.