Symfony2 does not run properly after being installed under nginx
阿神
阿神 2017-05-16 16:45:20
0
3
448

After installation, directly access http://localhost/Symfony/web/app_dev.... The welcome page will appear, but a prompt will pop up

An error occurred while loading the web debug toolbar (404: Not Found).Do you want to open the profiler?

But accessing http://localhost/Symfony/web/app_dev.... and http://localhost/Symfony/web/app_dev.... will return 404, please solve
symfony2

阿神
阿神

闭关修行中......

reply all(3)
左手右手慢动作

The problem has been solved because nginx does not know the pathinfo mode by default. Just configure it.

给我你的怀抱

The answer may be incorrect, I'm very sorry, you need to verify it

nginx does not configure pathinfo, it will be fine after configuring it

Open Nginx configuration file nginx.conf
Add the following configuration to the server:

Modify location ~ .php# to: ^/(app|app_dev|config).php(/|$)

^/(app|app_dev|config)\.php(/|$)

Add pathinfo parsing code, which is actually regular matching, and then add the following code


fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
set $real_script_name $fastcgi_script_name;
set $path_info ””;
if ( $fastcgi_script_name ~ “^(.+?.php)(/.+)$”)
{
    set $real_script_name ;
    set $path_info ;
} 
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info; 
}

Configuration is completed as follows


location ~ .php {  
root /www/;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9090;
fastcgi_index index.php;
include fastcgi_params; 

set $real_script_name $fastcgi_script_name;
set $path_info ””;
if ( $fastcgi_script_name ~ “^(.+?.php)(/.+)$”)
{
    set $real_script_name ;
    set $path_info ;
} 
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info; 
}

  • Note that if ( ) brackets need to be separated by spaces on both sides.

After modification, pathinfo can be recognized, but symfony still reports an error. Not solved yet.

刘奇

Looks like it’s time to expand your skills~ Level 4 and 6 are guaranteed, hahaha

server {
    listen         80;
    server_name    192.168.1.120;

    root  /data/nginx/htdocs/cwz;
    location / {
        index index.php index.html;
        root /data/nginx/htdocs/cwz;
    }

    index app.php index.html index.htm;

    try_files $uri $uri/ @rewrite;

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

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

        fastcgi_index app_dev.php;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;

        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;
        include fastcgi_params;
     }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template