[nginx] serves images very slowly

Hi all,

I am having an odd problem with serving images from a nginx server. on a first load the images often hang for ages until the server times outs, then on reload they get served in an instant. you can see it below in the wget log, first tries to load then gets stuck half way in between then restarts and the file loads in an instant. If I load a page with 20 images in the browser often images never finish to load.

--2012-11-28 20:42:47--  http://images.thomastraum.com/images/tumblr_me66gfgahO1qzt15co1_500.jpg
Resolving images.thomastraum.com... 178.79.178.99
Connecting to images.thomastraum.com|178.79.178.99|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 147449 (144K) [image/jpeg]
Saving to: `tumblr_me66gfgahO1qzt15co1_500.jpg'

55% [=============================================================================================================================>                                                                                                       ] 81,640      --.-K/s   in 65s     

2012-11-28 20:43:52 (1.23 KB/s) - Connection closed at byte 81640\. Retrying.

--2012-11-28 20:43:53--  (try: 2)  http://images.thomastraum.com/images/tumblr_me66gfgahO1qzt15co1_500.jpg
Connecting to images.thomastraum.com|178.79.178.99|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 147449 (144K), 65809 (64K) remaining [image/jpeg]
Saving to: `tumblr_me66gfgahO1qzt15co1_500.jpg'

100%[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++======================================================================================================>] 147,449     --.-K/s   in 0.05s   

2012-11-28 20:43:53 (1.24 MB/s) - `tumblr_me66gfgahO1qzt15co1_500.jpg' saved [147449/147449]

There is no traffic on the server as its just for development at the moment, I am using nginx as a proxy in front of a node js / express site, here is my conf

#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  10480;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    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/logs/nginx.log  main;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    #keepalive_requests 10000;
    keepalive_timeout  65;
    keepalive_disable none;

    gzip  on;
    gzip_comp_level 6;
    gzip_vary on;
    gzip_min_length  1000;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

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

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

then i have a second conf for my node site:

upstream images_upstream {
        server 127.0.0.1:3000;
}

server {
        listen 80;
        server_name images.thomastraum.com images;
        access_log /var/log/nginx/images.log;

        location ~  \.(jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
          root /home/tommi/sites/now-images-manager/public;
          access_log off;
          expires 30d;
        }

        location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;

          proxy_pass http://images_upstream/;
          proxy_redirect off;
        }
}

judging from some googling I am not the only one with this problem but different suggestions I tried all dont seem to work. Any help greatly appreciated!

1 Reply

According to your wget you're getting a .jpg file however .jpg isn't in your location directive, .jpeg is so your request is bing passed upstream to node.

You might want to consider using location /images or try files instead

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct