# X-Accel-Redirect issues - Image of 0 size

**URL:** <https://www.ruby-forum.com/t/x-accel-redirect-issues-image-of-0-size/193832>\
**Category:** NGINX\
**Created:** [August 25, 2010, 8:37am UTC](https://www.ruby-forum.com/t/x-accel-redirect-issues-image-of-0-size/193832 "2010-08-25T08:37:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![habodal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a6a055/32.png) [@habodal](https://www.ruby-forum.com/u/habodal)\
**Post date:** [August 25, 2010, 8:37am UTC](https://www.ruby-forum.com/t/x-accel-redirect-issues-image-of-0-size/193832/1 "2010-08-25T08:37:39Z")

</div>

Hello,

I am trying to use the X-Accel-Redirect header feature of Dokuwiki.  
However, when attempting to access images, for example, I receive an  
image of zero size which the browsers displays as a URL. I believe my  
nginx configuration is to blame.

Nginx config:

server {

```
    listen 80;

    server_name dev;

    root /var/www/public_html/dev/public;
    index index.php;
    autoindex on;

    location ~ \.php$ {
    include /usr/local/etc/nginx/fastcgi.conf;
    fastcgi_pass unix:/tmp/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_ignore_headers X-Accel-Redirect;
    fastcgi_pass_header X-Accel-Redirect;
    }

```

location ^~ /doku/data {  
internal;  
alias /wiki/data;  
}

}

When I attempt to access  
[http://dev/doku/lib/exe/fetch.php?cache=&media=image.jpg](http://dev/doku/lib/exe/fetch.php?cache=&media=image.jpg) (on filesystems  
as /var/www/public\_html/dev/public/doku/data/media/image.jpg) the  
browser displays the following text with an image mimetype:

[http://dev/doku/lib/exe/fetch.php?cache=&media=image.jpg](http://dev/doku/lib/exe/fetch.php?cache=&media=image.jpg)

The headers received are:

Server: nginx  
Date: Wed, 25 Aug 2010 06:06:42 GMT  
Content-Type: image/jpeg  
Expires: Thu, 26 Aug 2010 06:06:42 GMT  
Cache-Control: public, proxy-revalidate, no-transform, max-age=86400  
Pragma: public  
Last-Modified: Mon, 23 Aug 2010 17:01:22 GMT  
Content-Disposition: inline; filename=“image.jpg”;  
X-Accel-Redirect:  
/var/www/public\_html/dev/public/doku/data/media/image.jpg

200 OK

In the access log the request is shown as:  
“GET /doku/lib/exe/fetch.php?cache=&media=image.jpg HTTP/1.1” 499 0  
“[http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg](http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg)”  
“GET /doku/lib/exe/fetch.php?cache=&media=image.jpg HTTP/1.1” 200 5  
“[http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg](http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg)”

I see the X-Accel-Redirect and correct mimetype headers are sent. Along  
with the image not displaying, shouldn’t X-Accel-Redirect header read:

X-Accel-Redirect: /wiki/data/media/image.jpg

due to the alias directive?

What am I doing wrong?

Posted at Nginx Forum:

> **[X-Accel-Redirect issues - Image of 0 size](https://forum.nginx.org/read.php?2,123375,123375#msg-123375)**
>
> Hello, I am trying to use the X-Accel-Redirect header feature of Dokuwiki. However, when attempting to access images, for example, I receive an image of zero size which the browsers displays as a URL. I believe my nginx configuration is to blame....

---

<div class="post-metadata">

**Author:** ![habodal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a6a055/32.png) [@habodal](https://www.ruby-forum.com/u/habodal)\
**Post date:** [August 25, 2010, 10:22am UTC](https://www.ruby-forum.com/t/x-accel-redirect-issues-image-of-0-size/193832/2 "2010-08-25T10:22:26Z")

</div>

Hello!

On Wed, Aug 25, 2010 at 02:35:22AM -0400, habodal wrote:

> ```
> fastcgi_pass unix:/tmp/php-fpm.sock;
> fastcgi_index index.php;
> fastcgi_ignore_headers X-Accel-Redirect;
> fastcgi_pass_header X-Accel-Redirect;
> 
> ```

Your fastcgi\_ignore\_headers and fastcgi\_pass\_header instruct nginx  
to ignore X-Accel-Redirect header completely (i.e. do not handle  
it) and pass it back to client. It’s probably not what you want.

Just remove these two directives.

Maxim D.

---

<div class="post-metadata">

**Author:** ![habodal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a6a055/32.png) [@habodal](https://www.ruby-forum.com/u/habodal)\
**Post date:** [August 25, 2010, 6:03pm UTC](https://www.ruby-forum.com/t/x-accel-redirect-issues-image-of-0-size/193832/3 "2010-08-25T18:03:13Z")

</div>

Hello!

On Wed, Aug 25, 2010 at 11:40:07AM -0400, habodal wrote:

> host: “dev”, referrer:  
> "[http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg](http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg)
> 
> The webroot, /var/www/public\_html/dev/public/ appears twice in the  
> file’s path. How can I prevent this?

Looks like you return file path in X-Accel-Redirect. You should  
return uri instead, i.e.

X-Accel-Redirect: /docu/data/media/image.jpg

Maxim D.

---

<div class="post-metadata">

**Author:** ![habodal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a6a055/32.png) [@habodal](https://www.ruby-forum.com/u/habodal)\
**Post date:** [August 25, 2010, 5:41pm UTC](https://www.ruby-forum.com/t/x-accel-redirect-issues-image-of-0-size/193832/4 "2010-08-25T17:41:32Z")

</div>

Thank you, I guess I misunderstood those directives’ functions.

After removing them, now I receive a 404 when attempting to access the  
image. The error log shows:

[error] 1109#0: \*40 open()  
“/var/www/public\_html/dev/public/var/www/public\_html/dev/public/doku/data/media/image.jpg”  
failed (2: No such file or directory), client: 192.168.1.121, server:  
dev, request: “GET /doku/lib/exe/fetch.php?cache=&media=image.jpg  
HTTP/1.1”, upstream: “fastcgi://unix:/usr/local/var/run/php-fpm.sock:”,  
host: “dev”, referrer:  
"[http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg](http://dev/doku/lib/exe/detail.php?id=start&media=image.jpg)

The webroot, /var/www/public\_html/dev/public/ appears twice in the  
file’s path. How can I prevent this?

Posted at Nginx Forum:

> **[Re: X-Accel-Redirect issues - Image of 0 size](https://forum.nginx.org/read.php?2,123375,123601#msg-123601)**
>
> Hello, I am trying to use the X-Accel-Redirect header feature of Dokuwiki. However, when attempting to access images, for example, I receive an image of zero size which the browsers displays as a URL. I believe my nginx configuration is to blame....
