Question

Can't serve static files on my droplet running Ghost with Nginx, keep getting 404 error

I have a droplet running Ghost on Ubuntu 18.04 with Nginx. I’m trying to set up a way to serve static assets for my website, Javascript files, images, stuff like that. I’ve followed a few guides and no matter what I keep getting a 404 error when I try to access any files.

This is my Nginx configuration which is at /etc/nginx/sites-enabled/www.james-warren.com.conf

# HTTP server (non-www) -- redirect to https://James-warren.com
server {
    listen 80;
    server_name James-warren.com;
    return 301 https://www.James-warren.com$request_uri;
}

# HTTP server (www) -- redirect to https://James-warren.com
server {
    listen 80;
    server_name www.James-warren.com
    return 301 https://www.James-warren.com$request_uri;
}

# HTTPS server (www) -- redirect to https://James-warren.com -- Add HSTS header
server {
    listen 443 ssl;
    server_name www.James-warren.com;
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
    return 301 https://www.James-warren.com$request_uri;
}

server {
    listen 80;
    listen [::]:80;

    server_name www.james-warren.com;
    root /var/www/ghost/system/nginx-root;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }
    # For serving static files
    location /static/ {
        root /var/www/static/;
    }

    location ~ /.well-known {
        allow all;
     }


    client_max_body_size 50m;
}

This is what my file structure looks like: https://i.imgur.com/khVc8ER.png


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Did you try hosting your static files where you initially installed ghost as nginx only acts as a proxy for ghost at the moment and i’m not sure if the location parameter has any effect at all.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.