Sergey  Pekar Sergey Pekar - 2 months ago 88
PHP Question

Nginx Net::ERR_INCOMPLETE_CHUNKED_ENCODING when trying to show large JSON

Hello I am trying to show large json using php but when JSON file is large I get

Net::ERR_INCOMPLETE_CHUNKED_ENCODING
and see


"/var/lib/nginx/fastcgi/1/00/0000000001" failed (13: Permission
denied) while reading upstream


in my nginx log.

My nginx server starts as from www-data user.

ps aux | grep nginx
root 1 0.0 0.0 95592 8872 ? Ss 12:08 0:00 nginx: master process nginx -g daemon off;
www-data 7 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 8 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 9 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 10 0.0 0.0 95960 5600 ? S 12:08 0:00 nginx: worker process
www-data 11 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 12 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 13 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 14 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 15 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 16 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 17 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 18 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 19 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 20 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 21 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 22 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 23 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 24 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 25 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 26 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 27 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 28 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 29 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 30 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 31 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 32 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 33 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 34 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 35 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 36 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 37 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
www-data 38 0.0 0.0 95592 3868 ? S 12:08 0:00 nginx: worker process
root 55 0.0 0.0 8868 776 ? S+ 12:14 0:00 grep --color=auto nginx


also my php-fpm7 also works form www-data

/var/lib/nginx/ also owned by www-data.

ls -l nginx
total 20
drwxrwxrwx 2 www-data www-data 4096 Aug 21 21:35 body
drwxrwxrwx 2 www-data www-data 4096 Aug 21 21:35 fastcgi
drwxrwxrwx 2 www-data www-data 4096 Aug 21 21:35 proxy
drwxrwxrwx 2 www-data www-data 4096 Aug 21 21:35 scgi
drwxrwxrwx 2 www-data www-data 4096 Aug 21 21:35 uwsgi


php memory limit is 512m
nginx body limit is 100m

the server runs usign docker.

My nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 1024;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 2;
client_max_body_size 100m;
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_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

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

gzip on;
gzip_disable "MSIE [1-6].(?!.*SV1)";

gzip_vary on;
gzip_proxied any;
gzip_min_length 1000;
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;

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


Output of stat command

stat /var/lib/nginx/fastcgi
File: '/var/lib/nginx/fastcgi'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 40h/64d Inode: 140 Links: 2
Access: (0777/drwxrwxrwx) Uid: ( 1000/www-data) Gid: ( 33/www-data)
Access: 2016-08-30 11:30:16.268311861 +0000
Modify: 2016-08-21 21:35:34.000000000 +0000
Change: 2016-08-30 11:19:47.711701034 +0000
Birth: -


What can be wrong?

Answer

Finally fixed by removing /var/lib/nginx/fastcgi directory and then recreating it from root and changing it's owner to www-data.

now it looks like that

drwxr-xr-x 2 www-data root     4096 Sep  5 13:58 fastcgi

Also the problem could be fixed by adjusting fastcgi buffer size using these configuration settings:

    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
Comments