# Nginx can't read images

**URL:** <https://www.ruby-forum.com/t/nginx-cant-read-images/203783>\
**Category:** NGINX\
**Created:** [February 27, 2011, 5:49am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783 "2011-02-27T05:49:01Z")\
**Posts on this page:** 10\
**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:** [February 27, 2011, 5:49am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/1 "2011-02-27T05:49:01Z")

</div>

Hi,  
So it seems that mginx can’t read a url with .png, for example  
[http://20.16.31.42/phpMyAdmin/themes/original/img/logo\_right.png](http://20.16.31.42/phpMyAdmin/themes/original/img/logo_right.png)  
that gives me a page not found. The ip address above has been changed  
(not the original one), it’sjust to give illustration. I checked that  
the file logo\_right.png is in fact in that folder. What do I need to do  
to solve this?

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 27, 2011, 7:41am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/2 "2011-02-27T07:41:25Z")

</div>

What permissions do you have set on the folder? And how are you  
directing requests to the folder? Can you show us ur config?

Sent from my BlackBerry device on the Rogers Wireless Network

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 27, 2011, 4:37pm UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/3 "2011-02-27T16:37:10Z")

</div>

Is it also possible to change my php directive to:  
location ~ .php$ { root html;  
fastcgi\_pass 127.0.0.1:9000; fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME html$fastcgi\_script\_name;  
include fastcgi\_params; }  
?? Will it do the same?

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 27, 2011, 1:51pm UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/4 "2011-02-27T13:51:48Z")

</div>

On Sun, Feb 27, 2011 at 04:47:00AM +0000, Aditya H. wrote:

Hi there,

> So it seems that mginx can’t read a url with .png, for example

nginx usually does exactly what you tell it to. In this case…

> [http://20.16.31.42/phpMyAdmin/themes/original/img/logo\_right.png](http://20.16.31.42/phpMyAdmin/themes/original/img/logo_right.png)  
> that gives me a page not found. The ip address above has been changed (not the  
> original one), it’sjust to give illustration. I checked that the file  
> logo\_right.png is in fact in that folder. What do I need to do to solve this?

…what folder is the file logo\_right.png in?

Your config tells nginx to look for

/usr/local/nginx/html/phpMyAdmin/themes/original/img/logo\_right.png

but your config also suggests that you wanted to tell nginx to look for

/usr/share/nginx/html/phpMyAdmin/themes/original/img/logo\_right.png

Each (sub)request in nginx in handled by one location{} block, so you  
must make sure that the correct config is in the location block that is  
used for this specific request. Your location{} for .png urls uses the  
compile-time document root value.

If this server is new, and not used for other files or services, then  
the best change is probably to remove all “root” directives from your  
nginx.conf, and add a single “root /usr/share/nginx/html;” outside all  
location{}s, just after “server\_name localhost;”

Otherwise, you should probably add a “location /phpMyAdmin/ {}” which  
contains other location{}s for the new urls you care about.

Note also that the distributed phpMyAdmin includes a few .htaccess files  
to attempt to limit access to some files. There’s nothing in your config  
to mimic that, so unless you’ve taken other steps, you may be exposing  
more that the phpMyAdmin developers consider wise.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 28, 2011, 12:49am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/5 "2011-02-28T00:49:36Z")

</div>

The folder should have read access… I don’t know what you mean by  
redirecting requests to folder. I just noticed that it can’t also read  
css, js, and png, jpg!!  
Here’s my error log:  
011/02/27 05:53:29 [error] 18679#0: \*225 open()  
“/usr/local/nginx/html/phpMyAdmin/js/mooRainbow/mooRainbow.css” failed  
(2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/js/mooRainbow/mooRainbow.css  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:53:29 [error] 18679#0: \*226 open()  
“/usr/local/nginx/html/phpMyAdmin/print.css” failed (2: No such file or  
directory), client: 70.176.18.156, server: localhost, request: “GET  
/phpMyAdmin/print.css HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:53:29 [error] 18679#0: \*228 open()  
“/usr/local/nginx/html/phpMyAdmin/themes/original/img/logo\_right.png”  
failed (2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/themes/original/img/logo\_right.png  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:53:29 [error] 18679#0: \*223 open()  
“/usr/local/nginx/html/phpMyAdmin/themes/original/img/b\_help.png” failed  
(2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/themes/original/img/b\_help.png  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:53:29 [error] 18679#0: \*227 open()  
“/usr/local/nginx/html/phpMyAdmin/themes/original/img/s\_warn.png” failed  
(2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/themes/original/img/s\_warn.png  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:53:29 [error] 18679#0: \*227 open()  
“/usr/local/nginx/html/phpMyAdmin/favicon.ico” failed (2: No such file  
or directory), client: 70.176.18.156, server: localhost, request: “GET  
/phpMyAdmin/favicon.ico HTTP/1.1”, host: “50.56.81.42”  
2011/02/27 05:54:39 [error] 18679#0: \*237 open()  
“/usr/local/nginx/html/phpMyAdmin/print.css” failed (2: No such file or  
directory), client: 70.176.18.156, server: localhost, request: “GET  
/phpMyAdmin/print.css HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:54:39 [error] 18679#0: \*235 open()  
“/usr/local/nginx/html/phpMyAdmin/js/mooRainbow/mooRainbow.css” failed  
(2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/js/mooRainbow/mooRainbow.css  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:54:39 [error] 18679#0: \*238 open()  
“/usr/local/nginx/html/phpMyAdmin/themes/original/img/logo\_right.png”  
failed (2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/themes/original/img/logo\_right.png  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:54:39 [error] 18679#0: \*239 open()  
“/usr/local/nginx/html/phpMyAdmin/themes/original/img/b\_help.png” failed  
(2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/themes/original/img/b\_help.png  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
2011/02/27 05:54:39 [error] 18679#0: \*233 open()  
“/usr/local/nginx/html/phpMyAdmin/themes/original/img/s\_warn.png” failed  
(2: No such file or directory), client: 70.176.18.156, server:  
localhost, request: “GET /phpMyAdmin/themes/original/img/s\_warn.png  
HTTP/1.1”, host: “50.56.81.42”, referrer:  
“[http://50.56.81.42/phpMyAdmin/main.php](http://50.56.81.42/phpMyAdmin/main.php)”  
Here’s my config:  
#user nobody;  
worker\_processes 1;

#error\_log logs/error.log;  
#error\_log logs/error.log notice;  
#error\_log logs/error.log info;

#pid logs/nginx.pid;

events {  
worker\_connections 1024;  
}

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

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

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

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.(js|css|png|jpg|jpeg|gif|ico|html)$ {
             expires max;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 

```

127.0.0.1:9000  
#  
location ~ .php$ {  
root /usr/share/nginx/html;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME  
/usr/share/nginx/html$fastcgi\_script\_name;  
include fastcgi\_params;  
}

```
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one

    location ~ /\.ht {
        deny all;
    }
}

# another virtual host using mix of IP-, name-, and port-based 

```

configuration  
#  
#Server {  
# listen 8000;  
# listen somename:8080;  
# server\_name somename alias another.alias;

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

# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers 

```

ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  
# ssl\_prefer\_server\_ciphers on;

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

```

}

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 27, 2011, 4:56pm UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/6 "2011-02-27T16:56:39Z")

</div>

On Feb 27, 2011, at 18:35 , Aditya H. wrote:

> ?? Will it do the same?  
> Please read this  
> [How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration)

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 28, 2011, 1:16am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/7 "2011-02-28T01:16:04Z")

</div>

Above server\_name localhost;

- root html;

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 28, 2011, 1:20am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/8 "2011-02-28T01:20:07Z")

</div>

I don’t get it…what do you mean?

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 28, 2011, 1:27am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/9 "2011-02-28T01:27:46Z")

</div>

thanks it works now…can you explain what’s going on

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [February 28, 2011, 1:31am UTC](https://www.ruby-forum.com/t/nginx-cant-read-images/203783/10 "2011-02-28T01:31:31Z")

</div>

sorry, but no… I tried again and it still failed…it’s the caching  
that makes it like it works

From: removed\_email\_address@domain.invalid  
To: removed\_email\_address@domain.invalid  
Date: Sun, 27 Feb 2011 07:23:30 +0000  
Subject: RE: nginx can’t read images

thanks it works now…can you explain what’s going on
