Piszu
Piszu

Reputation: 443

Symfony, nginx and "File not found."

I have problem with nginx instance on OVH serwer.

When I go to my page i have error "File not found.".

/etc/nginx/sites-available/defaul from official Symfony configuration: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html#nginx

server {
    server_name 51.255.193.179;
    root /root/www/harccal/web;

    location / {
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

error_log:

2016/01/13 23:57:04 [crit] 9372#0: *9 stat() "/root/www/harccal/web/" failed (13: Permission denied), client: 89.70.84.185, server: 51.255.193.179, request: "GET / HTTP/1.1", host: "51$
2016/01/13 23:57:04 [crit] 9372#0: *9 realpath() "/root/www/harccal/web" failed (13: Permission denied), client: 89.70.84.185, server: 51.255.193.179, request: "GET / HTTP/1.1", host: $
2016/01/13 23:57:04 [error] 9372#0: *9 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 89.70.84.185, server: 51.255.193.179, request: "$

prem:

:~/www/harccal# ls -al
total 1332
drwxr-xr-x  8 root root    4096 sty 13 22:02 .
drwxr-xr-x  3 root root    4096 sty 13 21:51 ..
drwxr-xr-x  6 root root    4096 sty 13 22:24 app
drwxr-xr-x  2 root root    4096 sty 13 22:13 bin
-rw-r--r--  1 root root    2669 sty 13 21:51 composer.json
-rw-r--r--  1 root root   67193 sty 13 22:13 composer.lock
-rwxr-xr-x  1 root root 1248055 sty 13 22:02 composer.phar
drwxr-xr-x  8 root root    4096 sty 13 21:51 .git
-rw-r--r--  1 root root      80 sty 13 21:51 .gitignore
-rw-r--r--  1 root root      85 sty 13 21:51 README.md
drwxr-xr-x  4 root root    4096 sty 13 21:51 src
drwxr-xr-x 16 root root    4096 sty 13 22:24 vendor
drwxrwxr-x  7 root root    4096 sty 13 22:03 web

/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

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

        ##
        # Gzip Settings
        ##

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

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

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

I dont have more logs. or I dont know when find it..

Upvotes: 2

Views: 10053

Answers (2)

Andreas Kitzing
Andreas Kitzing

Reputation: 11

I had the same issue. After 3 hours of debugging, changing permissions back and forth, restarting everything I noticed that my local app.php was not uploaded to the remote host.

So if you run into the same error, one of several solutions can be to ensure that all your local files are correctly uploaded to your virtual host.

Upvotes: 0

zerkms
zerkms

Reputation: 255155

/root directory by default does not have read permissions by other users, which is pretty much reasonable. And most likely it has 700 permissions.

What happens next - your webserver user www-data tries to read files in /root/www/harccal/web. But the first directory in the chain (/root) is not readable by it. So it terminates with 9 stat() "/root/www/harccal/web/" failed (13: Permission denied)

For a file to be readable - every parent directory must be traversable as well.

Solution: you better move your application to another directory, that is accessible by a webserver user.

Upvotes: 3

Related Questions