web-dev-qa-db-ja.com

PHP + NGINX構成でダウンロードサイズに一貫性がない

ドキュメント管理/ダウンロードにdocmanを使用してJoomlaWebサイトを構築しています。このサイトは、Nginx 1.4.2およびPHP5(FPM)を実行しているUbuntu14.04サーバー上に構築されています。

私が抱えている問題は、ファイルのダウンロードに一貫性がないことです(サイズの点で)。たとえば、PDFファイルをWebサイトから6回ダウンロードしたところ、次の結果が得られました。

  • 72KB
  • 75KB
  • 146KB
  • 177KB(完全なファイル)
  • 72KB
  • 177KB(完全なファイル)

このテストでは、ファイル全体が6回のうち2回正しくダウンロードされました。他の4回のファイルは不完全でした。

私のnginx.confは次のようになります

user       www-data;
worker_processes  1;
error_log  logs/error.log;
worker_rlimit_nofile 8192;

events {
        worker_connections  4096;
}

http {
        include    /etc/nginx/conf/mime.types;
        include    /etc/nginx/proxy.conf;
        include    /etc/nginx/fastcgi.conf;
        index    index.php app.php index.html index.htm;
        default_type application/octet-stream;
        log_format   main '$remote_addr - $remote_user [$time_local]  $status '
        '"$request" $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';
        access_log   logs/access.log  main;
        sendfile     on;
        tcp_nopush   on;
        server_names_hash_bucket_size 128; # this seems to be required for some vhosts

        keepalive_timeout 0;

        #GZIP#
        gzip on;
        gzip_http_version 1.1;
        gzip_comp_level 6;
        gzip_min_length 1100;
        gzip_buffers 4 8k;
        gzip_types text/plain application/xhtml+xml text/css application/xml application/xml+rss text/javascript application/javascript application/x-javascript
        gzip_proxied     any;
        gzip_disable     "MSIE [1-6]\.";

        include /etc/nginx/sites-enabled/*;

サイトの構成は次のようになります。

server {
        listen 80;
        server_name example.com;
        server_name_in_redirect off;

        access_log /var/log/nginx/localhost.access_log main;
        error_log /var/log/nginx/localhost.error_log info;

        root /www/sites/canmore.link/html;
        index index.php index.html index.htm default.html default.htm;
        # Support Clean (aka Search Engine Friendly) URLs
        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        # deny running scripts inside writable directories
        location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
                return 403;
                error_page 403 /403_error.html;
        }

        location ~ \.php$ {
                        include fastcgi_params;
                        fastcgi_read_timeout 300;
                        fastcgi_intercept_errors on;
                        fastcgi_pass 127.0.0.1:9000;
        }


        # caching of files
        location ~* \.(ico|pdf|flv)$ {
                expires 1y;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
                expires 14d;
        }

}

これがログファイルです http://Pastebin.com/br0u36xp

2015/11/15 23:51:06 [info] 16075#0: *1 recv() failed (104: Connection reset by peer) while sending to client, client: 24.64.69.223, server: canmore.link, request: "$
2015/11/15 23:51:07 [crit] 16075#0: *3 open() "/var/lib/nginx/fastcgi/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 24.64.69.223, $
2015/11/16 00:24:09 [info] 16228#0: *68 recv() failed (104: Connection reset by peer) while sending to client, client: 24.64.69.223, server: canmore.link, request: $
2015/11/16 00:24:10 [crit] 16228#0: *70 open() "/var/lib/nginx/fastcgi/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 24.64.69.223,$
2015/11/16 00:31:46 [info] 16262#0: *1 recv() failed (104: Connection reset by peer) while sending to client, client: 24.64.69.223, server: canmore.link, request: "$
2015/11/16 00:31:53 [crit] 16262#0: *5 open() "/var/lib/nginx/fastcgi/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 24.64.69.223, $
2015/11/16 00:38:24 [error] 16318#0: *4 open() "/www/sites/canmore.link/html/favicon.ico" failed (2: No such file or directory), client: 24.64.69.223, server: canmo$
2015/11/16 00:38:24 [info] 16318#0: *1 client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 24.64.6$
2015/11/16 00:38:51 [info] 16318#0: *17 client 24.64.69.223 closed keepalive connection (104: Connection reset by peer)
2015/11/16 00:38:52 [crit] 16318#0: *14 open() "/var/lib/nginx/fastcgi/3/00/0000000003" failed (13: Permission denied) while reading upstream, client: 24.64.69.223,$
2015/11/16 00:38:55 [crit] 16318#0: *13 open() "/var/lib/nginx/fastcgi/4/00/0000000004" failed (13: Permission denied) while reading upstream, client: 24.64.69.223,$
2015/11/16 00:39:23 [info] 16360#0: *1 recv() failed (104: Connection reset by peer) while sending to client, client: 24.64.69.223, server: canmore.link, request: "$
2015/11/16 00:39:23 [crit] 16360#0: *3 open() "/var/lib/nginx/fastcgi/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 24.64.69.223, $
2015/11/16 00:40:33 [info] 16388#0: *44 recv() failed (104: Connection reset by peer) while sending to client, client: 24.64.69.223, server: canmore.link, request: $
2015/11/16 00:40:34 [crit] 16388#0: *46 open() "/var/lib/nginx/fastcgi/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 24.64.69.223,$
2015/11/16 00:40:44 [crit] 16388#0: *48 open() "/var/lib/nginx/fastcgi/2/00/0000000002" failed (13: Permission denied) while reading upstream, client: 24.64.69.223,$
2
Jonathan Coe

ログファイルに基づいて解決された問題...

/ var/lib/nginx/fastcgiフォルダーのアクセス許可を変更しましたが、機能しました。

chown -R www-data /var/lib/nginx/fastcgi
0
Jonathan Coe