custom 404 nginx + php-fpm

shaktale nginx-forum at nginx.us
Wed Jul 29 12:49:10 MSD 2009


Hi all.

I have the folllowing config:

  
# static files without rewrite
  location ~ ^.+\.(js|jpe?g|gif|png|css)$ {
        # 404 
        try_files  $uri /index.php;
        expires 1d;
  }

  location / {
     rewrite ^/(.+)_(.+)/(.+)/$ /index.php/action1/$1/action2/$2/action3/$3 last;
     rewrite ^(/.+_.+/.+)([^/])$ $1$2/ permanent;

     try_files $uri /index.php?$args;
  }

  # PHP
  location ~ ^(.+\.php.*)$ {
    fastcgi_split_path_info         ^(.+\.php)(.*)$;
    fastcgi_pass   127.0.0.1:9000;

    include /usr/local/nginx/conf/fastcgi_params;
    fastcgi_param  PATH_INFO        $fastcgi_path_info;
    fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
  }


I want to handle 404 errors with application (index.php). 

Works fine, except urls with php files, ie mydomain.com/foo.php

The foo.php is passed to fcgi, and php-fpm returns "No input file specified." 

If I use try_file in the "location ~ ^(.+\.php.*)$", then, the rewrites stops working. An error_page does not work either.

Any ideas ? 

Thanks in advance.

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






More information about the nginx mailing list