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

This is the site config based on official Symfony2 doc

server {
    listen 80;

    server_name     project.local;
    root            /media/Storage/project/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

server {
    listen 443;

    server_name     project.local;
    root            /media/Storage/project/web;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/localhost.crt;
    ssl_certificate_key /etc/nginx/ssl/localhost.key;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS on;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

At first, I was getting No input file specified. error, however I've read on nginx wiki that for this config I don't need the cgi.fix_pathinfo=0 (actually, they say Symfony2 needs it to be cgi.fix_pathinfo=1).

So I've changed it back to default (1) and now I'm getting File not found..

I've seen other questions where they suggest to use location ~ \.php$ {, however they were not meant for Symfony2 app.

I'd like to stick with the Symfony2 official config if possible.

Why is this happening, and what is the solution?

EDIT 1:

I've changed the cgi.fix_pathinfo back to 0 and changed the config to this:

server {
    listen 80;

    server_name     project.local;
    root            /media/Storage/project/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    location ~ "^(.+\.php)($|/)" {
        fastcgi_split_path_info ^(.+\.php)(.*)$;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

server {
    listen 443 ssl;

    server_name     project.local;
    root            /media/Storage/project/web;

    ssl_certificate     /etc/nginx/ssl/localhost.crt;
    ssl_certificate_key /etc/nginx/ssl/localhost.key;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    location ~ "^(.+\.php)($|/)" {
        fastcgi_split_path_info ^(.+\.php)(.*)$; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

Then restarted nginx and php5-fpm, as suggested on IRC, however, getting the famous Input file not specified error.

EDIT 2: this is the error.log

2014/06/25 22:11:45 [error] 11922#0: *3 FastCGI sent in stderr: "Unable to open primary script: /media/Storage/project/web/app_dev.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: project.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "project.local"

EDIT 3: this is access.log

127.0.0.1 - - [25/Jun/2014:22:11:45 +0200] "GET /app_dev.php HTTP/1.1" 404 56 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/34.0.1847.116 Chrome/34.0.1847.116 Safari/537.36"

The symfony2 log files are empty. I don't think symfony was ever executed.

EDIT 4: I've changed my confing following this SO anwser to:

server {
    listen 80;

    server_name     project.local;
    root            /media/Storage/project/web;

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location / {
        index app.php;
        if (-f $request_filename) {
          break;
        }
        rewrite ^(.*)$ /app.php last;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ (app|app_dev).php {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param HTTPS off;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

server {
    listen 443 ssl;

    server_name     project.local;
    root            /media/Storage/project/web;

    ssl_certificate     /etc/nginx/ssl/localhost.crt;
    ssl_certificate_key /etc/nginx/ssl/localhost.key;

    error_log /var/log/nginx/ssl_error.log;
    access_log /var/log/nginx/ssl_access.log;

    location / {
        index app.php;
        if (-f $request_filename) {
            break;
        }
        rewrite ^(.*)$ /app.php last;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ (app|app_dev).php {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

And now I'm getting Access denied. error. Yay, something changed :). Boo, not working yet :(.

EDIT 5: I've chown loostro:www-data /media/Storage/project -R and then chmod g+s /media/Storage/project -R, still getting Access denied

EDIT 6: The /var/run/php5-fpm.sock permissions are:

srw-rw---- 1 www-data www-data 0 cze 26 11:03 php5-fpm.sock

The /etc/php5/fpm/pool.d/www.conf file is the default (for Ubuntu 14.04 distro), except these changes I've uncommented following a tutorial:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660
share|improve this question
    
Is it a 404 Page not found error? What software generates the error? What are the entries in access.log and error.log? –  Tero Kilkanen Jun 25 at 19:53
    
I believe it's php5-fpm that generates this error. –  loostro Jun 25 at 19:56
    
In your config you dont add the index directive,, maybe that fail. –  Skamasle Jun 25 at 20:00
    
Without all log entries (nginx access.log, error.log, Symfony logs) we cannot help you. –  Tero Kilkanen Jun 25 at 20:05
    
added error log and access log –  loostro Jun 25 at 20:15

1 Answer 1

SUMMARY: My issue was wrong file permissions. The official symfony2 config for nginx is OK. I moved my files to an NTFS Storage drive, and it seems during the move file permissions were changed.

  • chown loostro:www-data -R /media/Storage/project - change owner to loostro and group to www-data (loostro is my user under which I develop the app, php5-fpm runs as www-data), recursively
  • chmod 755 -R /media/Storage/project - change file permissions for project to rwx (owner) rx (group, other), recursively
  • cd /media/Storage/project enter my project directory
  • chmod 775 -R app/cache app/logs web/uploads private/uploads - change file permissions for uploadable directories rwx (owner,group) and rx (other), recursively
  • chmod g+s -R /media/Storage/project - keep user and group & file permissions for newly created files in directories, recursively
share|improve this answer

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.