2013-12-18 91 views
3

我在Windows 7(64位)上運行,用PHP 5.4.12和1.5.8 Nginx的。的Nginx和FastCGI下載PHP文件,而不是處理它們

我已經設置此功能,並解決此問題,這是從我的本地請求PHP文件時,下載它作爲一個文件,而不是顯示PHP頁面看了很多教程。以下是我的nginx.conf文件:

worker_processes 1; 

events { 
    worker_connections 1024; 
} 

http { 
    include  mime.types; 
    default_type application/octet-stream; 

    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 

    #gzip on; 

    server { 
     listen 8081; 
     server_name localhost; 
     access_log C:/nginx/logs/access.log; 
     error_log C:/nginx/logs/error.log; 
     root C:/nginx/html; 

     fastcgi_param REDIRECT_STATUS 200; 

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

} 

我正在通過命令提示符手動運行nginx.exe。 我還試圖在一個單獨的命令提示手動第一起始PHP-cgi.exe文件,像這樣:

C:\php5.4.12\php-cgi.exe -b 127.0.0.1:9000 

我請求PHP文件是內C:/ nginx的/ HTML,我請求它爲:

http://localhost:8081/info.php 

然後下載它。這個PHP文件的內容是:

<?php 
phpinfo(); 
?> 

我怎樣才能讓我的PHP腳本在這個環境下運行。任何人都有這方面的經驗?

回答

3

嘗試將default_type application/octet-stream;更改爲default_type text/html; 也許您的php-script沒有設置內容MIME類型,並且它來自nginx。

+0

嘿,這工作!非常感謝Ashot! –

+0

不客氣!(: –

+0

有趣的,但它也爲我工作將是巨大的聽到這個高科技的解釋... – f055

0

試着將「*」這裏

location ~* \.php$ { 

有一些錯誤的路徑,nginx的不知道通過URL訪問的路徑是不是應該通過「fastcgi_pass」的路徑。因此,它提供了下載文件。

檢查您的錯誤日誌:

C:/nginx/logs/error.log; 

你有一個 「C:/nginx/html/info.php;」?

相關問題