搜尋

首頁  >  問答  >  主體

nginx下安裝symfony2 後運作不正常

安裝好後,直接造訪http://localhost/Symfony/web/app_dev.... 會出現welcome頁面,但會彈出一個提示

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

但這樣訪問 http://localhost/Symfony/web/app_dev.... 與 http://localhost/Symfony/web/app_dev.... 都會回傳404,求解
symfony2

阿神阿神2819 天前473

全部回覆(3)我來回復

  • ringa_lee

    ringa_lee2017-05-16 16:47:20

    問題已經解決,是因為nginx 預設不知從pathinfo模式, 配置一下就好了。

    回覆
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 16:47:20

    答案可能不正確,非常抱歉,還需要驗證一下

    nginx沒有設定pathinfo,設定後就可以了

    開啟Nginx的設定檔nginx.conf
    在server中加入一下設定:

    修改 location ~ .php# 為:^/(app|app_dev|config).php(/|$)

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

    加入pathinfo解析程式碼,其實就是正規匹配,後面接著加上以下程式碼

    
    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; 
    }
    

    配置為完成如下

    
    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; 
    }
    
    
    • 注意if ( ) 括號兩邊需要空格隔開。

    修改以後以後可以辨識pathinfo但是symfony 還是報錯。暫時沒解決。

    回覆
    0
  • 怪我咯

    怪我咯2017-05-16 16:47:20

    看來是時候放大招了~ 四六級包過啊 哈哈哈

    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;
         }
    }
    

    回覆
    0
  • 取消回覆