DEVOPS , LINUX

Ghost (blogging platform) on Fedora (21)

#fedora , #nginx

About two weeks ago I switched my blog to Ghost. Previously I used Pelican but Ghost is easier for me and has better themes ;-) I don’t want to waste my time for creating my own template or checking changes in Pelican because my configuration doesn’t work with a new release. I want to focus on blog posts.

Let’s back to the main topic. I will describe how to setup Ghost on Fedora using Nginx and Supervisor. I assume that you already have configured domain name with some server.

  1. Install Npm, Nginx and Supervisor.

    su -c 'yum install npm nginx supervisor'
    
  2. Download a Ghost application. I will store the blog in projects/blog in home directory.

    mkdir ~/projects
    cd ~/projects
    mkdir blog
    wget https://ghost.org/zip/ghost-latest.zip -O ghost.zip
    unzip -uo ghost.zip -d blog
    cd blog
    npm install --production
    
  3. Edit configuration file - config.js I’ve changed only domain name in production url variable. Part of config.js file, look at line with http://eshlox.net:

    config = {
    // ### Production
    // When running Ghost in the wild, use the production environment
    // Configure your URL and mail settings here
    production: {
        url: 'http://eshlox.net',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },
        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        }
    },
    
  4. Configure Nginx. Please create a configuration file in /etc/nginx/conf.d/, for example /etc/nginx/conf.d/blog.conf. Paste and modify this configuration:

    server {
        listen 80;
        server_name domain.com www.domain.com;
        access_log /var/log/nginx/domain.com_access.log;
        error_log /var/log/nginx/domain.com_error.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;
        }
    }
    

    Of course you need to change server_name, access_log, error_log and proxy_pass if you changed it in Ghost file configuration (127.0.0.1:2368 is a default).

  5. Configure Supervisor to keep the Ghost running. Create a configuration file in /etc/supervisord.d/, for example /etc/supervisord.d/blog.ini. Paste and modify this configuration:

    [program:blog]
    command = node /home/YOUR_USER/projects/blog/index.js
    directory = /home/YOUR_USER/projects/blog
    user = YOUR_USER
    autostart = true
    autorestart = true
    stdout_logfile = /var/log/supervisor/domain.com_out.log
    stderr_logfile = /var/log/supervisor/domain.com_err.log
    environment = NODE_ENV="production"
    

    As in previous point, change command, directory, user, stdout_logfile, stderr_logfile lines according to your needs.

  6. Start Nginx and Supervisor.

    su -c 'systemctl start nginx'
    su -c 'systemctl start supervisord'
    
  7. Go to your domain. Ghost blog should be running and work correctly.

Let me know if something is wrong. I’ve written that mostly from my head using my own configuration files.