Welcome! Log In Create A New Profile

Advanced

Nginx times out after Unoconv fails to convert XLSX to PDF

Posted by anujagg 
Nginx times out after Unoconv fails to convert XLSX to PDF
April 18, 2017 09:26AM
We use Unoconv to convert XLSX files to PDF and the same is done by calling Unoconv as:

putenv('PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/node/bin');
$tmp_path = '/home/around/libreoffice_tmp';
$tmp_output_file = '/home/around/libreoffice_tmp/output.txt';
$cmd = 'echo ' . $tmp_path . ' & echo $PATH & UNO_PATH=/usr/lib/libreoffice & /usr/bin/unoconv --format pdf --output ' . $output_file_pdf . ' ' . $output_file_excel . ' 2> ' . $tmp_output_file;
$output = '';
$result_var = '';
exec($cmd, $output, $result_var);

Request flows from our web application using Codeigniter 2.x / PHP 5.5 and Nginx 1.4.6 running on Ubuntu 14.04. LibreOffice 4.2.8.2 420m0(Build:2) and Unoconv 0.6 is installed.

Generally we don't face any issue and XLSX files get converted to PDF. But sometimes, this piece of code fails (we don't see log below this code in our log files) and Nginx starts returning time out (504 error) to our users.

If I do htop at that time, I find the CPU load very low and ~700MB+ RAM available out of 7GB. Mysql also responds to the requests placed directly to it through terminal. But everything fails when requests come through Nginx.

Ultimately, I need to restart FPM to make things work again:

sudo service php5-fpm restart

I checked nginx error logs in /var/log/nginx/ but could not find anything there. I checked error log in /var/www/mydomainname.com/logs/error.log and found:

2017/04/12 14:36:10 [error] 1871#0: *45903 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:36:12 [error] 1871#0: *45903 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:36:16 [error] 1871#0: *45903 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:40:02 [error] 1869#0: *46395 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:41:41 [error] 1870#0: *46448 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:41:45 [error] 1870#0: *46452 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:48:42 [error] 1869#0: *47276 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:49:34 [error] 1869#0: *47332 open() "/var/www/mydomainname.com/public_html/partner/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /partner/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/partner/login"
2017/04/12 14:50:08 [error] 1869#0: *47366 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:50:27 [error] 1869#0: *47381 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:51:22 [error] 1870#0: *47418 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 122.177.19.147, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:51:24 [error] 1871#0: *47468 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:51:44 [error] 1871#0: *47539 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:52:11 [error] 1869#0: *47633 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:52:23 [error] 1869#0: *47838 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com"
2017/04/12 14:52:27 [error] 1869#0: *47838 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com"
2017/04/12 14:52:39 [error] 1871#0: *47996 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 122.177.19.147, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:52:53 [error] 1869#0: *48042 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com"

I had also enabled nginx slow error logs and mysql slow logs but could not find anything there as well.

libreoffice_tmp/output.txt had these errors which I could not fix:

mkstemp("/var/www/.execooo7qvnSr") failed: Permission denied

As of now, we have stopped using unoconv and the 504 error has not come so far. But we need to convert our files to PDF so we need to enable it again.

Is there something which we have done wrong? Can a system call failure results in Nginx hang? Is there some other log file I should look at? Please help as even after spending so much time in debugging this issue, we are still clueless.

Nginx config file is:

server {
listen 80;
server_name mydomainname.com;
rewrite ^ https://$server_name$request_uri? permanent;
}

server {
listen 443;
# listen 80;
server_name www.mydomainname.com;
access_log /var/www/mydomainname.com/logs/access.log;
error_log /var/www/mydomainname.com/logs/error.log;
root /var/www/mydomainname.com/public_html;
index index.html index.htm index.php;
ssl on;
ssl_certificate /etc/nginx/mydomainname_ssl_3jul2016/mydomainname_final.crt;
ssl_certificate_key /etc/nginx/mydomainname_ssl_3jul2016/server.key;

##To _disable SSLv3, your ssl_protocols directive should be _set like this##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# proxy_cache one; this needs to be commented

location ~* .(jpg|jpeg|png|gif|ico|css|js|woff|ttf)$
{
expires 1h;
}
location / { try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/images/") {
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;

#fastcgi_read_timeout 300;

}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 286
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready