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

Hello i would like set up nginx like I want. I have read a lot of manuals (including official) but i can't make it work as I expect.

I have next urls: /user/register, /user/login, /user/logout etc ... no any urls with php files.

So i would like to pass all non real file urls to fast-cgi server. Btw, fpm working in chroot.

This is my config file:

 server {

    listen   80; ## listen for ipv4

    server_name  domain;
    root   /var/www/domain/htdocs; 
    include /etc/nginx/security;

    fastcgi_read_timeout 6000;

    location / {
      try_files $uri $uri/ @php-fpm;

    location @php-fpm {
       fastcgi_pass unix:/tmp/php5-fpm.sock;

       include /etc/nginx/fastcgi_params;
       fastcgi_param DOCUMENT_ROOT /htdocs;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param PATH_INFO $fastcgi_script_name;

in nginx log i see:

 - - [31/May/2012:16:02:12 +0300] "GET /user/register HTTP/1.1" 403 46 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5"

in fpm log the next:

- -  31/May/2012:13:02:12 +0000GET /user/register403 /var/www/domain/htdocs/user/register 0.215 512 0.00%

I have Ubuntu 12.04 and nginx 1.1.19

P.S. On screen (in browser) i see only that text "No input file specified."

share|improve this question
up vote 0 down vote accepted
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

So, you see in logs exactly what you have configured. Probably, you want something like:

fastcgi_param SCRIPT_FILENAME /path/to/your/script.php;
share|improve this answer
you are absolutely right, thank you very much, and I solved that problem i got notification about you answer. In any case thank you. – nixer Jun 1 '12 at 11:24

You've misconfigured try_files. As you can see in your php-fpm log, the exact url is being passed to the PHP server, which then attempts to get a file with that name, which of course doesn't exist.

What you need to do is either a rewrite or just change the passed file and then handle the given url within that script.

Adapted from my own nginx config:

try_files $uri $uri/ index.php;

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;

This configuration will forward all .php files to php_fpm. If you'd rather that .php files are not accessible at all directly, you'll need to use internal, which would hide them from the outside world, though in most cases you don't need to.

Using this configuration, all requests will be forwarded to index.php. To extract data about the page the user wants to view, look into PHP's $_SERVER['REQUEST_URI']. If you'll be exploding that string by /, keep in mind that the first array entry will be empty.

share|improve this answer
Actually my final config looks like this My task is ro prevent even direct access to absolutely any php files, only clean urls, and all of them should be redirected to one file index.php (in my example i did not prevent access to php files yet) – nixer Jun 1 '12 at 11:30

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.