Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Trying to get nginx to work with the X-Accel-Redirect header. I'm getting this error:

*24 rewrite or internal redirection cycle while internally redirecting to "/app/index.php", client: 127.0.0.1, server: project.dev, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "project.dev"

nginx site conf:

server {
    listen      80;
    server_name project.dev;
    root        /www/project;

    location ^~ /f/ {
        internal;
        alias /www/project/files/;
    }

    location / {
        try_files $uri /app/index.php$is_args$args;
    }

    include php.conf;
    include apache.conf;
}

/www/project/app/index.php

<?php
header('X-Accel-Redirect: /f/image.jpg');
exit;

I added ^~ to the location block, because I thought that would terminate the matching of location blocks, and therefor solve this. This might be a misunderstanding from my part.

Any idea how to fix this?


Update with php.conf and apache.conf

php.conf:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include        fastcgi_params;
}

apache.conf:

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny  all;
}
share|improve this question
    
This configuration works fine for me. Please provide the contents of php.conf and apache.conf since they may be interfering. –  mgorven Feb 7 '13 at 21:10
    
@mgorven Updated Q –  Znarkus Feb 7 '13 at 21:13
    
Does the PHP page display if you remove the X-Accel-Redirect and just echo something? What URL are you accessing in the browser? What happens if you specifically access /app/index.php? –  mgorven Feb 7 '13 at 21:17
    
To be clear: you're hoping that when you go to the root in a browser, /www/project/files/image.jpg is served? –  nickgrim Feb 8 '13 at 16:28
add comment

2 Answers

You haven't told nginx what index file to look for.

Try adding

index index.php;

After the root directive.

share|improve this answer
    
I've done that in my nginx.conf: index index.html index.htm index.php; –  Znarkus Feb 13 '13 at 11:29
add comment
up vote 0 down vote accepted

Looks like I failed to restart my nginx server. When I returned to this a couple of days later, it was suddenly working, and I realized it must be after a reboot. Sorry for wasting your time.

Now if I only could make it send the correct Content-type header..

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.