2012-10-31 28 views
4

我想配置Nginx發送所有404到一個php文件進一步處理。我沒有工作。使用try_files我得到一個默認的404,沒有try_files我沒有指定輸入文件。這是我到目前爲止有:獲取Nginx調用PHP文件來處理404錯誤在php-fpm

server { 
    listen 192.168.100.44:80; 

    location/{ 
     index index.html; 
    } 
    root /var/www/test.example.com; 

    error_page 404    /404.php; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
     #try_files  $uri = 404; 
     fastcgi_pass unix:/tmp/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
} 

回答

6

答案是添加一行: fastcgi_intercept_errors上;

接着,爲了處理404並可能從PHP腳本返回不同的狀態代碼: error_page 404 /404.php; 不得不簡單地改爲: error_page 404 = /404.php;

感謝Nginx IRC頻道的好心人,他們花了幾分鐘的時間向我展示正確的方向。