Nginx loading images very slow

Question!

I am trying to load some high resolution images with Jpeg format and specs are 300dpi, 5000 x 5000 resolution in Django production. Following are my nginx settings at digitalocean:

upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /home/django/django_project;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name localhost;


    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/media/;
    }

    # your Django project's static files - amend as required
    location /static/django_project/ {
        alias /home/django/django_project/static/django_project/; 
    }
    # Django static images
    location /static/django_project/images {
        alias /home/django/django_project/static-only/django_project/images/;
    }


    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}

After Browsing cache enabled:

upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /home/django/django_project;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name mysite.com;


    keepalive_timeout 5;

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/media/;
    }

    # your Django project's static files - amend as required
    location /static/django_project/ {
        alias /home/django/django_project/static/django_project/; 
    }
    # Django static images
    location /static/django_project/images {
        alias /home/django/django_project/static-only/django_project/images/;
    }


    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}

My images on live site are very slow to be loaded. Please advise or ref to some useful resource to fix this.

Thanks



Answers
Please use nginx Cache, this will solve your problem..

https://www.nginx.com/blog/nginx-caching-guide/

You can also cache the images in browser too by enabling browser cache...

https://www.howtoforge.com/make-browsers-cache-static-files-on-nginx



This video can help you solving your question :)
By: admin