PDF Generation Timeout Issue in ERPNext Custom App on Apache/Nginx Docker Setup

I have installed a Frappe/ERPNext production instance on our Apache VM and have a custom app with a Python script that is encountering an issue.

When trying to generate PDF files via the script (generating PDFs through the ERPNext UI works fine), I get the following error:

frontend-1      | 2024/10/30 15:33:28 [error] 14#14: *16 upstream timed out (110: Connection timed out) while reading response header from upstream, client: [IP CENSORED], server: erpnext-prod.intern.[CENSORED].eu, request: "POST /api/method/erpnext_[CENSORED]_app.public.py.pdf_append_po_link.prepend_order_link HTTP/1.1", upstream: "http://[IP CENSORED]:8000/api/method/erpnext_[CENSORED]_app.public.py.pdf_append_po_link.prepend_order_link", host: "erpnext-prod.intern.[CENSORED].eu", referrer: "https://erpnext-prod.intern.[CENSORED].eu/"

Using manually added log statements, I discovered that the timeout occurs at this line in my pdf_append_po_link.prepend_order_link function (which I implemented myself):

order_link_pdf = get_pdf(order_link_html)  # Generate PDF from HTML content

This line uses the get_pdf method from frappe.utils.pdf.

Interestingly, I have a manual test instance where I develop and test our app. Both the test VM and the production VM (running Docker) have the same app version installed. The test instance works perfectly, but the production instance fails to generate the PDF, leading me to suspect that this might be an Apache/Nginx configuration issue rather than a code problem?

We have already increased the RAM and adjusted the Nginx timeout settings (inside the frontend container) without any effect.

Additionally, I created another Dockerized instance on a private server of mine with the same app, and it worked as expected again. The issue only occurs on our company’s VM Apache instance.

Our Apache logs are not very helpful either:

Production Instance:

[IP CENSORED] - - [23/Oct/2024:11:59:02 +0200] "POST /api/method/erpnext_[CENSORED]_app.public.py.pdf_append_po_link.prepend_order_link HTTP/1.1" 504 832 "https://erpnext-prod.intern.[CENSORED].eu/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"

So, a 504 Gateway Timeout, right?

Again, the test instance works as expected:

Test Instance:

[IP CENSORED] - - [23/Oct/2024:11:57:54 +0200] "POST /api/method/erpnext_[CENSORED]_app.public.py.pdf_append_po_link.prepend_order_link HTTP/1.1" 200 1236 "https://erpnext-test.intern.[CENSORED].eu/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"

Here are our Apache configuration settings:

Here is my site_config.json:

If anyone has any ideas on what the problem could be, I would really appreciate your help! Thank you :slight_smile:

What’s the name of the site? Is it frontend or actual site subdomain/domain?

It used to be “frontend”, following another post though someone suggested I rename it to “localhost”, which didn’t help and then I renamed the site name to our host name. The sitename is currently “erpnext-prod.intern.[CENSORED].eu”.

“intern” If this is internal domain only accessible via vpn, make sure the pods/containers/machines that generate the images can resolve https://{internal.site}/files/*

Try something like this, Yet another wkhtmltopdf thread - #16 by revant_one

This worked with docker compose “hostname”, Yet another wkhtmltopdf thread - #14 by Sch-Tim