C
C
Cyril2014-06-02 14:42:52
Django
Cyril, 2014-06-02 14:42:52

How to setup nginx for django-nginx-image ?

I want to resize images when rendering a page using ngx_http_image_filter_module from nginx. The backend application works correctly and gives me a url like this:

/resize/60/-/media/images/0ca9f852-4d4c-4d22-b681-323219654d0a.jpg

I need to catch this url with nginx and resize it. I’m tormented, it doesn’t work out in any way =(
There is an example in the off description , but caching is used there, which I don’t need now, and I can’t set it up, and I’m proxying to gunicorn, which is not in the example. In theory, I need everything - just add:
location ~* ^/resize/([\d\-]+)/([\d\-]+)/(.+)$ {
            alias /home/django/web/alpha/static_content/$3;
            image_filter resize $1 $2;
            image_filter_buffer 2M;
            error_page 415 = /empty;
        }

but nothing works, although the nginx config is eating. Please help! Here is my config:
upstream vuer.org {
    server localhost:12345 fail_timeout=0;
}

server {
    listen 80;
    server_name  www.myproject.ru;
    rewrite ^/(.*) http://myproject.ru$1 permanent;
}

server {
    listen 80;
    client_max_body_size 200m;
    server_name myproject.ru;
    access_log  /home/django/web/alpha/logs/alpha.access.log;
    keepalive_timeout 5;

    root /home/django/web/alpha/static_content;
    
    location / {
        proxy_pass http://myproject.ru;
    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/django/web/alpha/static_content/static/html;
    }

   location ~ ^/(static|media|css|js)/ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://myproject.ru;
            break;
        
        root /home/django/web/alpha/static_content;
        access_log   /home/django/web/alpha/logs/nginx-static.access1_log;
     }
    }
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question