ac130nz
By:
ac130nz

[HELP] How to change Ghost's subdirectory to /blog

June 20, 2017 380 views
Ghost Ubuntu

I am trying to get ghost to run from example.com/blog instead of just example.com

I am now getting a ghost 404 on http://example.com/blog/ and the default nginx home page on http://example.com/

I used DO's one click installer and had ghost running before I tried this. I have looked at all info I could find on DO and ghostforbeginners.com

This is what I did:

nano /etc/nginx/sites-available/ghost

changed the location / to location /blog here:

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

    server_name http://example.com; # Replace with your domain

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

    client_max_body_size 10G;

    location /blog {
        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;
    }
}

Then saved it and nano /var/www/ghost/config.js changed the production url be have http://example.com/blog/

 production: {
        url: 'http://example.com/blog/',
        mail: {},
        database: {
...

Then I restarted everything

sudo service nginx restart

These didn't work or help me: https://www.ghostforbeginners.com/how-to-install-ghost-in-a-subdirectory/ and https://www.digitalocean.com/community/questions/adding-ghost-blog-to-existing-website and https://www.digitalocean.com/community/questions/how-to-put-ghost-blog-as-subdirectory-on-page

1 Answer

Hi @ac130nz

Try this server-block instead, just like the article on Ghost for Beginners:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name example.com; # Should only be the domain, not with http

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

    location ^~ /blog {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }
}
Have another answer? Share your knowledge.