# Images not loading sometimes with NGINX as RP

**URL:** <https://www.ruby-forum.com/t/images-not-loading-sometimes-with-nginx-as-rp/217790>\
**Category:** NGINX\
**Created:** [March 13, 2012, 1:47pm UTC](https://www.ruby-forum.com/t/images-not-loading-sometimes-with-nginx-as-rp/217790 "2012-03-13T13:47:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 13, 2012, 1:47pm UTC](https://www.ruby-forum.com/t/images-not-loading-sometimes-with-nginx-as-rp/217790/1 "2012-03-13T13:47:22Z")

</div>

Hello NGINX users and devs,

it’s not the first time now, that I have the problem that some images  
are just not loading sometimes (only after a few refreshes, gif images  
in this case) with NGINX as reverse proxy. I haven’t figured out yet  
why, I’ve had this problem with the old 0.x branch a few years ago, even  
with the default config and now I have the same problem with the 1.x  
branch and an advanced config with caching enabled (doesn’t matter if I  
enable or disable it, have already tried that). Has anyone had the same  
problem before or has a clue why that could be?

Greetings

Posted at Nginx Forum:

> **[Images not loading sometimes with NGINX as RP](https://forum.nginx.org/read.php?2,223791,223791#msg-223791)**
>
> Hello NGINX users and devs, it's not the first time now, that I have the problem that some images are just not loading sometimes (only after a few refreshes, gif images in this case) with NGINX as reverse proxy. I haven't figured out yet why, I've...

---

<div class="post-metadata">

**Author:** ![Infinitnet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/9d8465/32.png) [@Infinitnet](https://www.ruby-forum.com/u/Infinitnet)\
**Post date:** [March 13, 2012, 1:54pm UTC](https://www.ruby-forum.com/t/images-not-loading-sometimes-with-nginx-as-rp/217790/2 "2012-03-13T13:54:35Z")

</div>

> Greetings

In order to be able to assist you we need the config. Without it it’s  
like  
shooting in the dark.

–appa

---

<div class="post-metadata">

**Author:** ![Infinitnet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/9d8465/32.png) [@Infinitnet](https://www.ruby-forum.com/u/Infinitnet)\
**Post date:** [March 13, 2012, 2:05pm UTC](https://www.ruby-forum.com/t/images-not-loading-sometimes-with-nginx-as-rp/217790/3 "2012-03-13T14:05:12Z")

</div>

As I said, I’ve also had this before with the default config. Anyway,  
here you go:

## nginx.conf

user nginx;  
worker\_processes 6;  
worker\_rlimit\_nofile 8000;

error\_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

events {  
worker\_connections 4096;  
use epoll;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;  
open\_file\_cache max=60000 inactive=300s;  
open\_file\_cache\_valid 360s;  
open\_file\_cache\_min\_uses 2;  
open\_file\_cache\_errors off;  
server\_names\_hash\_bucket\_size 64;

```
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;

client_body_temp_path /var/spool/nginx-client-body 1 2;
client_max_body_size 32m;
client_body_buffer_size 128k;
client_header_buffer_size 2k;
large_client_header_buffers 4 16k;

server_tokens off;

sendfile on;
tcp_nopush on;
tcp_nodelay off;

keepalive_timeout 3;
keepalive_requests 10;
client_body_timeout 5;
client_header_timeout 5;
send_timeout 5;

proxy_cache_path /var/cache/nginx levels=1:2

```

keys\_zone=nginxcache:10m inactive=10m max\_size=1000m;  
proxy\_temp\_path /var/cache/nginx/proxy;  
proxy\_cache\_key “$scheme://$host$request\_uri”;

```
gzip on;
gzip_http_version 1.0;
gzip_comp_level 1;
gzip_proxied any;
gzip_min_length 10;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/x-javascript text/xml

```

application/xml application/xml+rss text/javascript;  
gzip\_disable “MSIE [1-6].(?!.\*SV1)”;  
gzip\_vary on;

```
proxy_redirect off;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;

proxy_connect_timeout 30;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

include /etc/nginx/conf.d/*.conf;

```

}

## vhost.conf

upstream server {  
server 1.2.3.4:80 weight=1 fail\_timeout=30s;  
}

server {  
listen 80;  
server\_name .domain.com;  
access\_log /var/log/nginx/domain.com\_access.log;  
error\_log /var/log/nginx/domain.com.net\_error.log;

```
location / {
proxy_pass http://server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_cache nginxcache;
proxy_cache_valid 200 30m;
}

location ~*

```

.(jpg|png|gif|jpeg|css|js|swf|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {  
proxy\_cache\_valid 200 30m;  
expires 604800;  
proxy\_pass [http://server](http://server);  
proxy\_cache nginxcache;  
}

}

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,223791,223794#msg-223794](http://forum.nginx.org/read.php?2,223791,223794#msg-223794)
