I'm having issue when uploading file on production using meteor with nginx + passenger. I'm also using meteor files for uploading files. it worked great in development but i can't upload files in production. i got and error in browser console:
POST http://my-url/ net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
i found error in my passenger log file saying Not keep-aliving application session connection because application did not allow it here is the log:
[ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/HttpChunkedBodyParser.h:183 ]: [Client 63] ChunkedBodyParser: parsing new chunk [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/HttpChunkedBodyParser.h:123 ]: [Client 63] ChunkedBodyParser: chunk size determined: 982 bytes [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/HttpChunkedBodyParser.h:162 ]: [Client 63] ChunkedBodyParser: parsing 982 of 982 bytesof remaining chunk data; 0 now remaining [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:1416 ]: [FBC 0x7f71e801b670] Feeding 982 bytes [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:486 ]: [FBC 0x7f71e801b670] pushBuffer() completed: nbuffers = 1, bytesBuffered = 982 [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:554 ]: [FBC 0x7f71e801b670] Reader: reading next [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:586 ]: [FBC 0x7f71e801b670] Reader: found buffer, 982 bytes [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:493 ]: [FBC 0x7f71e801b670] popBuffer() completed: nbuffers = 0,bytesBuffered = 0 [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:594 ]: [FBC 0x7f71e801b670] Reader: feeding buffer, 982 bytes [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:554 ]: [FBC 0x7f71e801b670] Reader: reading next [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:561 ]: [FBC 0x7f71e801b670] Reader: no more buffers. Transitioning to RS_INACTIVE [ D3 2018-09-27 16:53:44.2194 2500/Ta Ser/FileBufferedChannel.h:539 ]: [FBC 0x7f71e801b670] Calling dataFlushedCallback [ D3 2018-09-27 16:53:44.2194 2500/Ta age/Cor/Con/ForwardResponse.cpp:64 ]: [Client 2-63] Event: onAppSourceData [ D3 2018-09-27 16:53:44.2194 2500/Ta age/Cor/Con/ForwardResponse.cpp:206 ]: [Client 2-63] Processing 7 bytes of application data: "\r\n0\r\n\r\n" [ D3 2018-09-27 16:53:44.2195 2500/Ta Ser/HttpChunkedBodyParser.h:248 ]: [Client 63] ChunkedBodyParser: done parsing a chunk [ D3 2018-09-27 16:53:44.2195 2500/Ta Ser/HttpChunkedBodyParser.h:183 ]: [Client 63] ChunkedBodyParser: parsing new chunk [ D3 2018-09-27 16:53:44.2195 2500/Ta Ser/HttpChunkedBodyParser.h:123 ]: [Client 63] ChunkedBodyParser: chunk size determined: 0bytes [ D3 2018-09-27 16:53:44.2195 2500/Ta Ser/HttpChunkedBodyParser.h:162 ]: [Client 63] ChunkedBodyParser: parsing 0 of 0 bytes of remaining chunk data; 0 now remaining [ D3 2018-09-27 16:53:44.2195 2500/Ta Ser/HttpChunkedBodyParser.h:164 ]: [Client 63] ChunkedBodyParser: end chunk detected [ D3 2018-09-27 16:53:44.2195 2500/Ta Ser/HttpChunkedBodyParser.h:267 ]: [Client 63] ChunkedBodyParser: end chunk reached [ D2 2018-09-27 16:53:44.2195 2500/Ta age/Cor/Con/ForwardResponse.cpp:224 ]: [Client 2-63] End of application response body reached [ D2 2018-09-27 16:53:44.2195 2500/Ta age/Cor/Con/ForwardResponse.cpp:1077 ]: [Client 2-63] Not keep-aliving application sessionconnection because application did not allow it [ D3 2018-09-27 16:53:44.2195 2500/Ta age/Cor/App/Socket.h:201 ]: Socket unix:/tmp/passenger.toEIX2t/apps.s/node.1si9u5: connection not checked back into connection pool. There are now 2 connections in total [ D2 2018-09-27 16:53:44.2195 2500/Ta age/Cor/App/Gro/SessionManagement.cpp:150 ]: Session closed for process (pid=2519, group=/var/www/hmn/bundle (production))
- Meteor 1.6.1
- Meteor-Files 1.9.11
- Ubuntu 16.04
- nginx 1.14.0
- passenger 5.3.5
- AWS
this is my nginx config file
user www-data; worker_processes 1; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; # tcp_nopush on; # tcp_nodelay on; server_tokens off; keepalive_timeout 65; types_hash_max_size 2048; server_names_hash_bucket_size 64; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "MSIE [1-6]\."; gzip_proxied any; gzip_http_version 1.0; gzip_min_length 500; gzip_types text/plain text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/atom+xml; include /etc/nginx/passenger.conf; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } // sites-enabled/* file server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://$host$request_uri; } server{ listen 443 default_server ssl; listen [::]:443 default_server ssl; ssl on; ssl_certificate /etc/ssl/mydomain.pem; ssl_certificate_key /etc/ssl/mydomain.key; ssl_dhparam /etc/ssl/dhparam.pem; server_name xxx.xxx.xxx.xxx; passenger_enabled on; passenger_sticky_sessions on; root /var/www/my_app/bundle/public; passenger_app_type node; passenger_startup_file main.js; passenger_env_var MONGO_URL mongodb://some_shard_urls; passenger_env_var ROOT_URL https://xxx.xxx.xxx.xxx; passenger_env_var MONGO_OPLOG_URL: mongodb://some_shard_urls; keepalive_timeout 1000; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GC$ ssl_stapling on; ssl_stapling_verify on; add_header Strict-Transport-Security "max-age=31536000;"; access_log /var/log/my_app/access.log; error_log /var/log/my_app/error.log; proxy_send_timeout 60s; location / { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_redirect off; client_max_body_size 100M; if ($uri != '/') { expires 30d; } break; } }
I'm using aws S3 to hosting the file and meteor files has feature to integrate with s3. here is my sample code:
const ProductAssets = new FilesCollection({ debug: false, collectionName: 'collection_name', allowClientCode: false, storagePath: './products', permissions: 0777, // debug: true, chunkSize: 'dynamic', parentDirPermissions: 0777, onBeforeUpload: function(file) { if (/png|jpe?g/i.test(file.extension)) { return true; } }, onAfterUpload(fileRef) { Meteor.call('upload.to.s3', fileRef) }, }); // upload to s3 method 'upload.to.s3': function(fileRef) { _.each(fileRef.versions, async (vRef, version) => { const filePath = 'products/' + fileRef._id + '/' + version + '-' + fileRef._id + '.' + fileRef.extension; await s3.putObject({ // ServerSideEncryption: 'AES256', StorageClass: 'STANDARD', Bucket: bucket, Key: filePath, Body: fs.createReadStream(vRef.path), ContentType: vRef.type }, (error, data) => { bound(() => { if (error) { console.error(error); } else { // Update FilesCollection with link to the file at AWS const upd = { $set: {} }; upd['$set']['versions.' + version + '.meta.pipePath'] = filePath; ProductAssets.collection.update({ _id: fileRef._id }, upd, (updError) => { if (updError) { console.error(updError); } else { // Unlink original files from FS after successful upload to AWS:S3 ProductAssets.unlink(ProductAssets.collection.findOne(fileRef._id), version); } }); } }) }); }) },
on side note, files that is being uploaded doesn't saved into database and s3 on production. on development, the files is saved and uploaded to s3 properly
anybody know how to fix it and explain what is wrong? thank you!
0 comments:
Post a Comment