解決 Nginx+PHP 環境中下載附件不完整


情況

  1. 通過 URL 直接下載檔案是完整沒問題的.
  2. 通過 php 讀取檔案後再輸出下載檔頭給予下載文件就不完整.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 打開相應域名的 error_log
vim /usr/local/nginx/conf/sub.domain.com.conf

error_log /usr/local/nginx/logs/sub.domain.com

# 瀏覽相應網站嘗試下載附件,應會見到這東西
2013/03/05 14:47:11 [crit] 12914#0: *11104565 open() "/usr/local/nginx/fastcgi_temp/0/64/0000002640" failed (13: Permission denied) while reading upstream, client: 119.246.195.117, server: sub.domain.com, request: "GET /xxxx.php?file=xxx HTTP/1.1", upstream: "fastcgi://127.0.0.1:1234", host: "sub.domain.com", referrer: "http://sub.domain.com/xxxx.php"

# 權限問題
# 刪掉原先在 fastcgi_temp 的所有子目錄,讓 nginx 再重建
rm -rf /usr/local/nginx/fastcgi_temp/*

# 為了安全起建將 fastcgi_temp 改為 700
# 對應的用戶和組應該就是 nginx:wheel 之類的
chmod -Rf 700 /usr/local/nginx/fastcgi_temp/