Nginx corrupts files on upload

I have a problem with my application built with php and Laravel Framework.

The problem is with uploading / downloading files.

When I upload files to the server, they save them well, but when I try to upload an uploaded file that is over 100KB in size, it just uploads part of it, causing it to get corrupted.

Tried many options tweaking php.ini settings, nginx settings and still couldn't solve it.

Here is my current configuration for 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/*;
}

      

Now here is my nginx site configurator:

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;
    }
}

      

Following are the related php.ini settings 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

      

And finally, here's my php script that downloads the file:

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();
}

      

Thanks for any help in advance!: D

+3


source to share


1 answer


I understood that!

I checked the error log for this nginx site and found this error:

*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

      



This error came from the fact that some time ago we changed the user to www-data in order to start services like php-fpm, but I forgot to change it for nginx.

Changed user to www-data and now everything works as it should!

Thank!

+3


source







All Articles