0

I have a CSV Download, with Docker, Nginx and PHP-FPM, everything runs fine, until downloads gets larger then 2-3 MB. The generated CSV files exists in the php container (in my tmp directory /var/www/symfony/var/tmp/... and looks fine), but Nginx cant serve them. Nginx error logs shows this

2019/05/09 12:09:29 [crit] 7#7: *747 open() "/var/tmp/nginx/fastcgi/2/07/0000000072" failed (13: Permission denied) while reading upstream, client: 172.18.0.1, server: , request: "GET /catalog-download HTTP/1.1", upstream: "fastcgi://172.18.0.3:9001", host: "localhost", referrer: "http://localhost/catalog"

Looks like my csv file is not there and Nginx or somebody should have moved them to the Nginx tmp folder.

There are some post about Nginx download problems, but most of them have problems with 300MB and larger. So I think my problem is different. Downlaods are fine, but are limited < ~2-3MB.

Nginx Config is

user www;

worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections  2048;
    multi_accept on;
    use epoll;
}

http {
    server_tokens off;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 15;
    types_hash_max_size 2048;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log off;
    error_log off;
    gzip on;
    gzip_disable "msie6";
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    open_file_cache max=100;
    client_body_temp_path /tmp 1 2;
    client_body_buffer_size 256k;
    client_body_in_file_only off;
    client_max_body_size 50M;
}

and

upstream php-upstream {
    server php:9001;
}

server {
    listen 80;
    server_name mydomain.tk;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name mydomain.tk;
    server_tokens off;

    ssl_certificate /etc/letsencrypt/live/mydomain.tk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain.tk/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /var/www/symfony/public;

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

    location ~ ^/.+\.php(/|$) {
        fastcgi_pass php-upstream;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        fastcgi_read_timeout 240;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

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

PHP FPM config is

[symfony]
user = www
group = www
listen = 0.0.0.0:9001
pm = dynamic
pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = yes
request_terminate_timeout = 240

changes in php.ini are

date.timezone = 'Europe/Berlin'
memory_limit = 512M

opcache.memory_consumption = 256
opcache.max_accelerated_files = 20000
opcache.validate_timestamps = 1
realpath_cache_size = 4096K
realpath_cache_ttl = 600

post_max_size = 50M
upload_max_filesize = 50M
max_execution_time = 240
sendmail_path = "/usr/bin/msmtp -t"

But at the moment, I dont think PHP-FMP has an issue, because csv files exists. It has something to do with missing file in the '/var/tmp/nginx/fastcgi/' folder.

I would be very happy about any help.

ABSimon
  • 651
  • 1
  • 6
  • 18

2 Answers2

0

luckily, I was able to find a solution, after reading this post

https://serverfault.com/questions/235154/permission-denied-while-reading-upstream

I added rights "chown www.www /var/tmp/nginx/" so nginx can use his tmp folder.

It seems like, nginx only needs is own tmp folder when files becomes larger than 2-3 MB. Very tricky. I assumed that rights existed, because small downloads worked...

ABSimon
  • 651
  • 1
  • 6
  • 18
0

Search the php.ini file for the following text:

; Whether to allow HTTP file uploads. file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not specified).

;upload_tmp_dir =

; Maximum allowed size for uploaded files. upload_max_filesize = 128M