Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:, server:, request: "GET / HTTP/1.1", upstream: "fastcgi://", host: ""

nginx site conf:

server {
    listen      80;
    root        /www/project;

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

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

    include php.conf;
    include apache.conf;


header('X-Accel-Redirect: /f/image.jpg');

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


# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$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;
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

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

Your Answer


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.