2016-07-30 63 views
0

這讓我感到莫名其妙。當我訪問域時,它下載index.php文件。當我訪問domain/index.php時,它工作正常。我試圖在這裏和那裏發表評論,但無法修復。這一個是Zend Framework 3。我在同一臺服務器上有其他的PHP網站。他們很好。我開始想知道現在是ZF3的特別之處。當按下域名時,PHP-FPM/ZF3下載php文件

我nginx的是這樣的:

server { 
    listen  80; 
    server_name xxx.xxx.com; 
    index index.php index.html; 
    root   /data/www/xxx/public; 

    location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    include  fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME /data/www/xxx/public/index.php; 
    } 

    access_log logs/worth.jusfeel.cn.log main; 
} 

我已經嘗試過其他的設置也是如此。一樣的。地址欄中的網址更改爲..domain/index.php,但仍下載index.php文件。

server { 
    listen  80; 
    server_name www.example.com; 
    root  /var/www/www.example.com/myapplication; 
    index  index.html index.htm index.php; 

    location/{ 
    try_files $uri $uri/ /index.php$is_args$args; 
    } 

    location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include  fastcgi_params; 
    } 
} 

回答

0

下載index.php文件意味着nginx的不使用PHP-FPM處理文件。這種情況背後的最常見原因是nginx和php-fpm之間的配置錯誤。

清單:

  1. 確保你沒有php.ini禁用cgi.fix_pathinfo指令。它提供了真實的PATH_INFO/PATH_TRANSLATED對CGI的支持,默認啓用(1)
  2. 確保您的虛擬主機的根目錄指向您的ZF3應用程序的public目錄。在這種情況下,你可能需要從/var/www/www.example.com/myapplication更換,以/var/www/www.example.com/myapplication/public
  3. 最重要的部分是你需要在location ~ \.php$ { }塊適當fastcgi_split_path_info指令,因爲通過index.php處理的所有PHP請求。此僞指令定義了一個正則表達式,該正則表達式捕獲nginx $fastcgi_path_info變量的值。

例如:

location ~ \.php$ { 
    fastcgi_pass   127.0.0.1:9000; 
    fastcgi_split_path_info ^(.+.php)(/.+)$; 
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include     fastcgi_params; 
} 

希望它能幫助。