NGINX config to block content from internal subsites being downloaded but not the main site

I have a WordPress Multisite network setup and I am trying to block non-registered users from being able to download PDFs and other documents from direct link to the internal sub sites.

To do this, I am using this in my NGINX config:

location ~ .(pdf|doc|docx|xls|xlsx)$ {
if ($http_cookie !~ “wordpress_logged_in”) {
return 403;
}
}

This works great except I have a few public documents on my main front page that can’t be downloaded.

How can I alter this code to only work on the subsites and be able to download from the front page?

Read more here:: NGINX config to block content from internal subsites being downloaded but not the main site

Leave a Reply

Your email address will not be published. Required fields are marked *