In 2018 and 2015 there were articles published for how to serve static files. I wanted to do the same, for my free (and hopefully one day soon paid) members.
For self-ghosters, Nginx can read the ghost cookies to serve files if a member is logged in. However, the cookie name contains dashes. There’s a little trick to map it to a variable Nginx can read.
- In your conf file: nano /etc/nginx/sites-enabled/ghost add the following above the server { }
map $http_cookie $ghostly_cookie {
default 0;
“~ghost-members-ssr.sig=(?[^;]+)” $mc;
}
2. Create your folder under /var/www/ghost/[your folder name]
- Under the other location entry add:
location /media/ {
if ($ghostly_cookie = 0) {return 401;}
alias /var/www/ghost/[your folder name]/;
}
Here are the blog and stack overflow sources for reading cookies with special characters:
Now, I’m working on creating a custom error message for 401 (unauthorized).