Есть ли примеры конфига кеширования статики в Django для Nginx?

Всем привет.

У меня гугл ругается на то, что нет Expire date на статику (css/js/media). Как выяснилось, мне нужно в nginx, прописать данную строчку. И что-то я туплю с тем, как это все должно выглядеть. Можете подсказать, какую строчки мне нужно дописать, чтобы все завертелось?

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {

	##
	# Gzip Settings
	##
	gzip on;
	gzip_disable "msie6";
	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 5;
	gzip_buffers 16 8k;
	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
	

	ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 5m;
    ssl_prefer_server_ciphers on;
    ssl_stapling on;
    resolver 8.8.8.8;
	
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen 443 ssl;
		ssl_certificate /etc/ssl/your_domain.crt;      
        ssl_certificate_key /etc/ssl/your_domain.key;  
        server_name bakot.ru www.bakot.ru;

        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/bakotiinii/bakot;
        }

        location  /media/ {
            root /home/bakotiinii/bakot/;
        }
        
        location  /robots.txt {
            root /home/bakotiinii/bakot/faceset/static;
        }

        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://unix:/home/bakotiinii/bakot/bakot.sock;
        }
		
		error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {        
		listen 80;
		server_name bakot.ru;
		return 301 https://$host$request_uri;        
    }
}
  • Вопрос задан
  • 236 просмотров
Пригласить эксперта
Ответы на вопрос 1
Terras
@Terras Автор вопроса
Поставил вот так, вроде заработало.

location /static/ {
            root /home/bakotiinii/lieman;
			access_log off;
			expires 15d; 
        }

        location  /media/ {
            root /home/bakotiinii/lieman/;
			access_log off;
			expires 15d;
        }


Это допустимый вариант?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы