Nginx directory listing is not working as intended - get ghost 404 page

Good day folks;

I’m running ghost alongside a static folder that needs to be able to respond to GET from a client downloader. This has worked in the past and I do not know what would cause this to break at this time.

The folder that is causing 404 errors (from ghost, not nginx) is located at:
/var/www/launcher

My ghost sites-enabled confs are below:

www.centerofthemultiverse.net.conf

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

    server_name www.centerofthemultiverse.net;
    root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

    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;

    }

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

    location /launcher {
        autoindex on;
    }

    client_max_body_size 50m;
}

www.centerofthemultiverse.net-ssl.conf

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name www.centerofthemultiverse.net;
    root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

    ssl_certificate /etc/letsencrypt/www.centerofthemultiverse.net/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/www.centerofthemultiverse.net/www.centerofthemultiverse.net.key;
    include /etc/nginx/snippets/ssl-params.conf;

    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;

    }

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

    location /launcher {
        autoindex on;
    }

    client_max_body_size 50m;
}

Any Ideas?

Please let me know what other information would be helpful.

Cheers!

I believe you’re missing a root declaration:

location /launcher {
    root /var/www/launcher;
    autoindex on;
}

The location /launcher refers to the request URL, nginx doesn’t know about folders on disk unless you tell it about them.

As it is, the root has been set at the top of the config:

root /var/www/ghost/system/nginx-root;

It might be that you want to drop that line into the location ~ /.well-known {} block (although I’ve not tested that before) and set your global root to /var/www/.

Thanks much for your reply!

Would you mind formatting this into the code blocks I provided, please? I’m having a bit of a hard time parsing what you are advising as to what changes need to be made and tested and I don’t want to mangle things further.

Also, when you say ‘set global root’ I assume you mean in the base nginx.conf? If so, I’ll need to write out an entire server block as current config does not have one.

Cheers!

The fix is to swap your location blocks that look like this

location /launcher {
    autoindex on;
}

To this:

location /launcher {
    root /var/www/launcher;
    autoindex on;
}

When I say “global root”, I mean the line I mentioned:

root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

It’s global to the server configuration file. I’m not talking about nginx.conf.

I think I got it now, thank you for clarifying!

Like so?:

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

    server_name www.centerofthemultiverse.net;
    root /var/www/

    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;
    }

    location ~ /.well-known {
    root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)
        allow all;
    }

    location /launcher {
    root /var/www/launcher;
    autoindex on;
    }

    client_max_body_size 50m;
}

nginx’s root directive tells the current scope (server or location block) where to look on disk.

The simplest solution is just to update your location /launcher {} block to have the correct root.

You can also change all the other roots around as you have done.

I would make one change at a time, and test them, until you get the behaviour you want.

Good news: No longer getting the ghost 404.
Bad news: Now I am getting the nginx 404

I think we are getting closer?

This result occurred by doing both proposed fixes. Both .conf are not set up like this - the blog still works, but still getting nginx 404:

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

server_name www.centerofthemultiverse.net;
root /var/www/;

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;

}

location ~ /.well-known {
    root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)
    allow all;
}

location /launcher {
root /var/www/launcher;
autoindex on;
}

client_max_body_size 50m;

}

Bumping - as said, the blog works but still getting 404 otherwise. Also getting 403 Forbidden when you omit the www on the address but that is a separate issue.

So, I ask - is this anything to do with how ghost configs nginx or is this strictly an nginx issue? Every nginx guide/resource I could find leads me to believe I have things configured properly so I am at a total loss at this point.

Shouldn’t it be /launcher/ if it’s a directory?

Sadly, that did not seem to work:

This is the following blurb in both ssl/regular conf files

location ~ /.well-known {
        root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)
        allow all;
    }

    location /launcher/ {
    root /var/www/launcher/;
    autoindex on;
    }