php-Nginx损坏了下载的文件

前端之家收集整理的这篇文章主要介绍了php-Nginx损坏了下载的文件 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我用PHP和Laravel框架制作的应用程序出现问题.

问题在于文件上传/下载.

当我向服务器提交文件时,它可以很好地存储它们,但是当我尝试下载大于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;
    }
}

然后是(/etc/PHP5/fpm/PHP.ini)中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

最佳答案
我想到了!.

我检查了此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-data以启动诸如PHP-fpm之类的服务,但我忘记为Nginx进行更改.

用户更改为www-data,现在一切正常.

谢谢!

原文链接:https://www.f2er.com/nginx/532273.html

猜你在找的Nginx相关文章