fst0pped
By:
fst0pped

Tutorial Issue: Multiple Ghost blogs on one VPS

January 6, 2016 2.1k views
Nginx Ghost DigitalOcean Articles

Hi - I followed the below tutorial to the letter, and I'm having trouble getting multiple blogs working correctly:

https://www.digitalocean.com/community/tutorials/how-to-serve-multiple-ghost-blogs-on-one-vps-using-nginx-server-blocks

When I reached the end both domains were pointing at the same instance of Ghost (I'd update the content on the domain1 blog and it would also appear on domain2. I'd try to log in on domain2 and it would throw an error telling me to log in from the URL specified in the config.js file).

I've gone through the comments and made a couple of other minor changes based on issues other users have had. I know sometimes the DO image gets updated and renders bits of the tutorial slightly out of date.

  • Removed 'default server' from the domain2 config files to prevent the 'duplicate default servers' error.
  • Set up files in '/etc/nginx/sites-enabled' as symlinks to the config files in '/etc/nginx/sites-available'

There seem to be a few others in the comments on the tutorial having this same issue, but no answers in the thread. Any idea whether something has changed in the image that is causing this? Or have I messed up something during set-up?

Thanks.

4 comments
  • Post your nginx conf and config.js

  • Thanks, c&p below. Have only taken the production sections of the config.js files.

    nginx.conf:

    user www-data;
    worker_processes 4;
    pid /run/nginx.pid;
    
    events {
        worker_connections 768;
        # multi_accept on;
    }
    
    http {
    
        ##
        # Basic Settings
        ##
    
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
    
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
    
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
    
        ##
        # Logging Settings
        ##
    
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
        ##
        # Gzip Settings
        ##
    
        gzip on;
        gzip_disable "msie6";
    
        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##
    
        #include /etc/nginx/naxsi_core.rules;
    
        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##
    
        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;
    
        ##
        # Virtual Host Configs
        ##
    
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    }
    
    

    config.js - domain1:

    var path = require('path'),
        config;
    
    config = {
        // ### Production
        // When running Ghost in the wild, use the production environment.
        // Configure your URL and mail settings here
        production: {
            url: 'http://www.blog.helloimandrew.co.uk',
            mail: {},
            database: {
                client: 'sqlite3',
                connection: {
                    filename: path.join(__dirname, '/content/data/ghost.db')
                },
                debug: false
            },
    
            server: {
                host: '127.0.0.1',
                port: '2368'
            }
        },
    

    config.js - domain2:

    // # Ghost Configuration
    // Setup your Ghost install for various [environments](http://support.ghost.org/config/#about-environments).
    
    // Ghost runs in `development` mode by default. Full documentation can be found at http://support.ghost.org/config/
    
    var path = require('path'),
        config;
    
    config = {
        // ### Production
        // When running Ghost in the wild, use the production environment.
        // Configure your URL and mail settings here
        production: {
            url: 'http://www.stuffandnonsense.me.uk',
            mail: {},
            database: {
                client: 'sqlite3',
                connection: {
                    filename: path.join(__dirname, '/content/data/ghost.db')
                },
                debug: false
            },
    
            server: {
                host: '127.0.0.1',
                port: '2777'
            }
        },
    
  • Those are okay. How about server blocks in sites-enabled?

  • Hi, sorry pasted the server blocks into the answer field below instead of the comments so you probably haven't seen them.

    Also was doing some experimenting tonight. If I swap the 'default server' markers from the sites-available domain1.conf to domain2.conf, both URLs then point to the domain2 instance of Ghost.

2 Answers

Files in sites-enabled are symlinks to sites-available, so these are from my sites-available.

domain1.conf

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

    server_name blog.helloimandrew.co.uk; # Replace with your domain

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:2368;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

domain2.conf

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

    server_name stuffandnonsense.me.uk; # Replace with your domain

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:2777;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

Really simple solution. server_name in the /etc/nginx/sites-available folder needed to include the 'www.' (which it doesn't in the tutorial).

Without that requests were being directed to the server's IP address and, because none of them matched any domains in the sites-available folder, were being passed to the default.

Many thanks for your time though! It's been a learning curve.

Have another answer? Share your knowledge.