X-Accel-Redirect issues - Image of 0 size

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 (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

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
“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

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:
http://forum.nginx.org/read.php?2,123375,123375#msg-123375

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.

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

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.

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

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

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,123375,123601#msg-123601

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs