0
votes

I am configurating a virtual hosts with nginx. When I put my address, the page return me this error: File not found. My configuration is the next:

server {
listen 80;
server_name vcarlos.lan;

root /home/tfc_dev/tfc/web;

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

index app.php index.html index.htm;

try_files $uri $uri/ @rewrite;

location @rewrite {
    rewrite ^/(.*)$ /app.php/$1;
}

location ~ \.php(/|$) {
    # try_files $uri =404;

    fastcgi_index app.php;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    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 SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffer_size   1280k;
    fastcgi_buffers   4 2560k;
    fastcgi_busy_buffers_size   2560k;
}

location ~ /\.ht {
    deny all;
}

}

EDIT #1 I have modified the code and I put the next:

    server {
    server_name vcarlos.lan;
    root /home/sierra/tfc_dev/tfc/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    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 $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fasserver {
    server_name vcarlos.lan;
    root /home/sierra/tfc_dev/tfc/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    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 $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
    # PROD
    location ~ ^/app\.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;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}tcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

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

Now it recognise Symfony2 but it return this error:

Oops! An Error Occurred The server returned a "404 Not Found". Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.*

1

1 Answers

0
votes

Please replace:

rewrite ^/(.*)$ /app.php/$1;

with:

rewrite ^/(.*)$ /app.php?query_string;

UPD: Try this one:

server {
        listen 0.0.0.0:80;
        server_name vcarlos.lan;
        root /home/tfc_dev/tfc/web;

        index app.php;
        try_files $uri $uri/ /app.php?$query_string;

        location ~ \.php$ {
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_pass php-fpm;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}