2015-04-20 43 views
3

我在使用php和Laravel框架創建應用程序時遇到問題。Nginx在下載文件時損壞了文件

問題出在文件上傳/下載。

當我提交文件到服務器它存儲他們很好,但是當我嘗試下載大於100KB的上傳文件時,它只是下載它的一部分,使其損壞。

通過調整php.ini設置,nginx設置嘗試了很多選項,仍然無法解決它。

這裏是我的nginx的當前配置:

nginx.conf

user developer; 
worker_processes 4; 
pid /run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 

    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 
    # server_tokens off; 

    server_names_hash_bucket_size 64; 
    # server_name_in_redirect off; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    ## 
    # SSL Settings 
    ## 

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 
    ssl_prefer_server_ciphers on; 

    ## 
    # Logging Settings 
    ## 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    ## 
    # Gzip Settings 
    ## 

    gzip on; 
    gzip_disable "msie6"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # Virtual Host Configs 
    ## 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

現在,這裏是我的nginx的站點配置:

server { 

    listen 8002 default_server; 
    server_name localhost 172.20.74.229 cadeco.dev; 

    root /var/www/current/cadeco/public; 
    index index.php index.html index.htm; 

    access_log /var/log/nginx/cadeco.dev-access.log; 
    error_log /var/log/nginx/cadeco.dev-error.log error; 

    charset utf-8; 

    include h5bp/basic.conf; 

    location = /favicon.ico { log_not_found off; access_log off; } 
    location = /robots.txt { log_not_found off; access_log off; } 

    location ~ /\. { 
     deny all; 
     access_log off; 
     log_not_found off; 
    } 


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

    sendfile off; 

    client_max_body_size 100m; 

    location ~ ^/index\.php(/|$) { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 

     include fastcgi.conf; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
    } 
} 

當年這裏是PHP相關的設置。 ini from(/etc/php5/fpm/php.ini):

max_execution_time = 30 
max_input_time = 60 

memory_limit = 512M 

upload_max_filesize = 50M 
max_file_uploads = 20 

最後,這裏是我的PHP腳本,它的文件下載:

public function downloadFile($file) 
{ 
    $filePath = storage_path('app/uploads/').$file; 

    if (Storage::exists($file)) 
    { 
     return response()->download($filePath); 
    } 

    Flash::error('File does not exists!'); 

    return redirect()->back(); 
} 

感謝您的幫助提前! :D

+0

而百萬美元的問題 - 你是如何確定它是腐敗的? –

+0

我已經用文本編輯器打開並將內容與原始內容進行比較,只是原始文件的一部分在下載的文件中。 – UxWeb

回答

3

我想通了!

我檢查錯誤日誌,這個nginx的網站,發現這個錯誤:

*10 open() "/var/lib/nginx/fastcgi/4/00/0000000004" failed (13: Permission denied) while reading upstream, client: 172.20.73.101, server: localhost, request: XXXXX 

該錯誤內容時發生,因爲前一段時間我們改變了用戶WWW的數據開始像PHP-FPM服務,但我忘了將它改爲nginx。

將用戶更改爲www-data,現在一切正常!

謝謝!