Nginx Net::ERR_INCOMPLETE_CHUNKED_ENCODING 试图显示大 JSON

Nginx Net::ERR_INCOMPLETE_CHUNKED_ENCODING when trying to show large JSON

你好我正在尝试使用 php 显示大 json 但是当 JSON 文件很大时我得到 Net::ERR_INCOMPLETE_CHUNKED_ENCODING看看

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

在我的 nginx 日志中。

我的 nginx 服务器从 www-data 用户启动。

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

我的 php-fpm7 也适用于 www-data

/var/lib/nginx/ 也归 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内存限制为512m nginx 主体限制为 100m

服务器运行 usign docker。

我的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/*;
}

stat 命令的输出

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: -

有什么问题吗?

最终通过删除 /var/lib/nginx/fastcgi 目录,然后从根目录重新创建它并将其所有者更改为 www-data 来修复。

现在看起来像那样

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

也可以通过使用这些配置设置调整 fastcgi 缓冲区大小来解决此问题:

    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;