A
A
Artyom2019-04-08 13:56:01
Django
Artyom, 2019-04-08 13:56:01

How to disable direct requests to nginx static files?

I need the styles of the project to be loaded in the html code of the page. Static files in django are usually located in static and are available under the /static/ path. However, I don't want anyone poking around in a directory with static files. How to do it? How to prevent get requests directly to .../static/some.js, but allow them for caching and Django?
Rule for static in nginx config:

location /static/ {
        autoindex off;
        alias /home/project/app/static/;
        expires 30d;
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2019-04-08
@kot_mapku3

No way. Maximum - you can block requests without a referral, but this is very easy to bypass.

T
TyzhSysAdmin, 2019-04-08
@POS_troi

No way.
Everything that is available to the client for download is available to him even in the body of the page, even through a direct link.
The maximum that can be done is to check the referee, but the meaning of this is about zero.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question