Static linked pages


In my 0.x Ghost blog, I had a directory called static at /var/www/static. In it I have several documents that I link to on a ghost page. I upgraded to the 1.x version by creating a new server and installing a new version of Ghost. I imported all my information and copied over the files in the static directory. Now my new version of Ghost gives me a 404 when I try a link to the static documents in the static directory.

I added

location /static/ {
alias /var/www/static;

to the ghost/system/blogname.conf file, restarted ghost and nginx but that didn’t fix the problem. I also tried:

location /files {
root /var/www/static;

but still no go.

What am I missing? Is there a different file I need to modify?


You’re missing a trailing slash (/) on your /static/ location block alias. Try this:

location /static/ {
    alias /var/www/static/;

Assuming your host is localhost, and you have a /var/www/static/doc.pdf, you’ll then be able to go to localhost/static/doc.pdf and have it served up.

If you wish to use root rather than alias, then you will need to omit the /static portion, otherwise it’ll end up searching for /var/www/static/static/doc.pdf (notice the double static directory). If you wish to use the root approach then you will want the following.

location /static/ {
    root /var/www/

Note the trailing slash at the end of the location and the root again.


Thanks for the suggestion, however that didn’t fix the problem. I have tried it with and without the trailing / in both the location statement and in the actual directory location. No variation I have tried works. I didn’t have this problem in my pre 1.x versions. I believe my issue is with the root statement in the config on ver 1.x. Here is my config from /var/www/ghost/system/files/mysite.conf

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

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;


location ~ /.well-known {
    allow all;
location /static/ {
   root /var/www/static/;

client_max_body_size 50m;

The root statement points to a directory that does not exist and is not symlinked. How does that work? You can see my location statement later in the file. I have used root and alias to identify the directory but neither option works. I’ve even tried to put the location statement in the nginx.conf file in hopes that would get read first. Not only am I out of ideas, I’m not sure I understand how the root directory even works. The only thing I haven’t tried is to clear the cache but to be honest, I can’t figure out where it is located.

Any help you could give me would be greatly appreciated.


@televoip What @elliot suggested works for me:

location /static/ {
    alias /var/www/static/;

Of course, remember to restart Nginx after each change:

sudo service nginx restart


I would suggest reloading the nginx config rather than restarting the service: sudo nginx -s reload

This theoretically is faster but more importantly has the benefit of falling back to the working configuration if yours isn’t valid


Yes, there is also the possibility of testing the changes before applying them:

sudo nginx -t

But usually I let Webmin’s Nginx module take care of this previous testing that I forgot to mention.

closed #7

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.