D0060ed3b0d6a3cce027d644bff338f3a7a6770c
By:
marmot7

ghost is mostly working except for default URL it seems

February 15, 2017 693 views
Ghost CentOS

When I go to my new blog using https://linuxhowto.tech/ it works just fine. When I click on home at the top it works fine.

When I click on the name of the blog and so on it goes to http://localhost:2368/

I can't see where to change it so URL will always be https://linuxhowto.tech/. I've looked through various config files and can't seem to find what will make this change.

in config.js the url is set to https://linuxhowto.tech just as the instructions call for.

4 Answers
jtittle1 February 15, 2017
Accepted Answer

@marmot7

The first thing I would recommend changing is this server block:

server {
    listen 80;
    server_name linuxhowto.tech;
    location / {
         return 301 https://$server_name$request_uri;
    }
}

When it comes to HTTP -> HTTPS redirects, you don't need to specify a location block. All you need to use is:

server {
    listen 80;
    server_name linuxhowto.tech;

    return 301 https://$server_name$request_uri;
}

Beyond that, I just setup and ran a test installation of Ghost + NGINX using your Proxy Config and it's working without any issues, so it may be the above that's causing the issues.

So for you domain, you should have two server blocks that look like:

server {
    listen 80;
    server_name linuxhowto.tech;

    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name linuxhowto.tech;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/linuxhowto.tech/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/linuxhowto.tech/privkey.pem;
    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;

    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;
    }
}
  • Cool. Thank you. I'll give this a try. I appreciate you going through the effort of replicating it. Any idea what might be causing the bad gateway error?

  • Okay i somehow left out a ; so now at least nginx stars properly again. Now we'll see if ghost and all the rest works!

@marmot7

Are you running Ghost on port 80, or trying to, or are you using a web server such as NGINX/Apache to proxy requests to http://localhost:2368?

If you'll post your config.js (comment out sensitive data) and, if using web server, the VirtualHost or Server Block details, we can take a look at those configurations and see what we can find.

  • I'm using Nginx to proxy requests but I'm not very experienced at this so I'm sure I'm doing something wrong. Here's my config.js. Thank you very much for your willingness to take a look.

    
    // # 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: 'https://linuxhowto.tech',
            mail: {},
            database: {
                client: 'sqlite3',
                connection: {
                    filename: path.join(__dirname, '/content/data/ghost.db')
                },
                debug: false
            },
    
            server: {
                host: '127.0.0.1',
                port: '2368'
            }
        },
    
        // ### Development **(default)**
        development: {
            // The url to use when providing links to the site, E.g. in RSS and email.
            // Change this to your Ghost blog's published URL.
            url: 'https://linuxhowto.tech',
    
            // Example refferer policy
            // Visit https://www.w3.org/TR/referrer-policy/ for instructions
            // default 'origin-when-cross-origin',
            // referrerPolicy: 'origin-when-cross-origin',
    
            // Example mail config
            // Visit http://support.ghost.org/mail for instructions
            // ```
            //  mail: {
            //      transport: 'SMTP',
            //      options: {
            //          service: 'Mailgun',
            //          auth: {
            //              user: '', // mailgun username
            //              pass: ''  // mailgun password
            //          }
            //      }
            //  },
            // ```
    
            // #### Database
            // Ghost supports sqlite3 (default), MySQL & PostgreSQL
            database: {
                client: 'sqlite3',
                connection: {
                    filename: path.join(__dirname, '/content/data/ghost-dev.db')
                },
                debug: false
            },
            // #### Server
            // Can be host & port (default), or socket
            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'
            },
            // #### Paths
            // Specify where your content directory lives
            paths: {
                contentPath: path.join(__dirname, '/content/')
            }
        },
    
        // **Developers only need to edit below here**
    
        // ### Testing
        // Used when developing Ghost to run tests and check the health of Ghost
        // Uses a different port number
        testing: {
            url: 'https://linuxhowto.tech',
            database: {
                client: 'sqlite3',
                connection: {
                    filename: path.join(__dirname, '/content/data/ghost-test.db')
                },
                pool: {
                    afterCreate: function (conn, done) {
                        conn.run('PRAGMA synchronous=OFF;' +
                        'PRAGMA journal_mode=MEMORY;' +
                        'PRAGMA locking_mode=EXCLUSIVE;' +
                        'BEGIN EXCLUSIVE; COMMIT;', done);
                    }
                },
                useNullAsDefault: true
            },
            server: {
                host: '127.0.0.1',
                port: '2369'
            },
            logging: false
        },
    
        // ### Testing MySQL
        // Used by Travis - Automated testing run through GitHub
        'testing-mysql': {
            url: 'https://linuxhowto.tech',
            database: {
                client: 'mysql',
                connection: {
                    host     : '127.0.0.1',
                    user     : 'root',
                    password : '',
                    database : 'ghost_testing',
                    charset  : 'utf8'
                }
            },
            server: {
                host: '127.0.0.1',
                port: '2369'
            },
            logging: false
        },
    
        // ### Testing pg
        // Used by Travis - Automated testing run through GitHub
        'testing-pg': {
            url: 'https://linuxhowto.tech',
            database: {
                client: 'pg',
                connection: {
                    host     : '127.0.0.1',
                    user     : 'postgres',
                    password : '',
                    database : 'ghost_testing',
                    charset  : 'utf8'
                }
            },
            server: {
                host: '127.0.0.1',
                port: '2369'
            },
            logging: false
        }
    };
    
    module.exports = config;
    
    • @marmot7

      If you would, please also post your NGINX server block for the domain.

      • # For more information on configuration, see:
        #   * Official English Documentation: http://nginx.org/en/docs/
        #   * Official Russian Documentation: http://nginx.org/ru/docs/
        
        user nginx;
        worker_processes auto;
        error_log /var/log/nginx/error.log;
        pid /run/nginx.pid;
        
        # Load dynamic modules. See /usr/share/nginx/README.dynamic.
        include /usr/share/nginx/modules/*.conf;
        
        events {
            worker_connections 1024;
        }
        
        http {
            log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                              '$status $body_bytes_sent "$http_referer" '
                              '"$http_user_agent" "$http_x_forwarded_for"';
        
            access_log  /var/log/nginx/access.log  main;
        
            sendfile            on;
            tcp_nopush          on;
            tcp_nodelay         on;
            keepalive_timeout   65;
            types_hash_max_size 2048;
        
            include             /etc/nginx/mime.types;
            default_type        application/octet-stream;
        
            # Load modular configuration files from the /etc/nginx/conf.d directory.
            # See http://nginx.org/en/docs/ngx_core_module.html#include
            # for more information.
            include /etc/nginx/conf.d/*.conf;
        
        server {
            listen 80;
            server_name linuxhowto.tech;
            location / {
                 return 301 https://$server_name$request_uri;
            }
        }
        
        server {
            listen 443 ssl;
            server_name linuxhowto.tech;
            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;
            }
            ssl on;
            ssl_certificate /etc/letsencrypt/live/linuxhowto.tech/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/linuxhowto.tech/privkey.pem;
            ssl_prefer_server_ciphers On;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
        }
        
        #personal website
        server {
            listen 80;
            server_name neilanuskiewicz.com;
            location / {
                 return 301 https://$server_name$request_uri;
            }
        }
        
        server {
            listen 443 ssl;
            server_name neilanuskiewicz.com;
            client_max_body_size 10G;
            root /var/www/html/neilanuskiewicz.com;
        
            index index.html;
        
            location / {
                try_files $uri $uri/ =404;
            }
            ssl on;
            ssl_certificate /etc/letsencrypt/live/neilanuskiewicz.com/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/neilanuskiewicz.com/privkey.pem;
            ssl_prefer_server_ciphers On;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
        }
        
        
        # Settings for a TLS enabled server.
        #
        #    server {
        #        listen       443 ssl http2 default_server;
        #        listen       [::]:443 ssl http2 default_server;
        #        server_name  _;
        #        root         /usr/share/nginx/html;
        #
        #        ssl_certificate "/etc/pki/nginx/server.crt";
        #        ssl_certificate_key "/etc/pki/nginx/private/server.key";
        #        ssl_session_cache shared:SSL:1m;
        #        ssl_session_timeout  10m;
        #        ssl_ciphers HIGH:!aNULL:!MD5;
        #        ssl_prefer_server_ciphers on;
        #
        #        # Load configuration files for the default server block.
        #        include /etc/nginx/default.d/*.conf;
        #
        #        location / {
        #        }
        #
        #        error_page 404 /404.html;
        #            location = /40x.html {
        #        }
        #
        #        error_page 500 502 503 504 /50x.html;
        #            location = /50x.html {
        #        }
        #    }
        
        }
        
        

I went ahead and restarted the droplet but somehow made the problem change to this:

502 Bad Gateway

LOL. From sort of working to flat out broken.

  • @marmot7

    Why that error shows will depend on how you've setup your Ghost installation. If you've not yet created a service script to start/stop/restart Ghost and you're still running it from the CLI using npm, that's a common error and may mean Ghost isn't ready just yet. You'd need to wait until the CLI echo's out that your Ghost installation is now ready.

    That said, if you've not setup a service script for Ghost, you'd effectively have to run two SSH instances, one for Ghost to continue running (as once you CTRL+C it kills the process) and one to restart/reload NGINX.

    The init script on the official Ghost website works well as I've used it in the past:

    http://support.ghost.org/deploying-ghost/

    ... and it'll allow you to run Ghost without having to keep the SSH session open.

    • it works now!!!!

      NODE_ENV=production pm2 start index.js --name "Ghost"

      Then I had to reinstall the theme but no big deal. Now it seems to work perfectly. I can't thank you enough.

@jtittleI think I marked one of your answers as accepted answer. I really, really appreciate your help. Thank you. It's been a bit of a long road but I'm happy to say that all is well that ends well. I now have a useable ghost blog that's https which was my goal for tonight.

  • @marmot7

    No problem at all, I enjoy helping :-). If you run in to any other issues, feel free to open a new thread and @ mention me in it.

Have another answer? Share your knowledge.