Apache上的Django - 防止504网关超时

时间:2022-06-18 21:28:49

I have a Django server running on Apache via mod_wsgi. I have a massive background task, called via a API call, that searches emails in the background (generally takes a few hours) that is done in the background.

我有一个通过mod_wsgi在Apache上运行的Django服务器。我有一个庞大的后台任务,通过API调用调用,在后台搜索后台(通常需要几个小时)的电子邮件。

In order to facilitate debugging - as exceptions and everything else happen in the background - I created a API call to run the task blocking. So the browser actually blocks for those hours and receives the results.

为了便于调试 - 作为异常以及后台发生的所有其他事情 - 我创建了一个API调用来运行任务阻止。因此,浏览器实际上会阻止这些时间并收到结果。

In localhost this is fine. However, in the real Apache environment, after about 30 minutes I get a 504 Gateway Timeout error.

在localhost这很好。但是,在真正的Apache环境中,大约30分钟后,我得到504网关超时错误。

How do I change the settings so that Apache allows - just in this debug phase - for the HTTP request to block for a few hours without returning a 504 Gateway Timeout?

如何更改设置以便Apache允许 - 仅在此调试阶段 - HTTP请求阻止几个小时而不返回504网关超时?

I'm assuming this can be changed in the Apache configuration.

我假设这可以在Apache配置中更改。

1 个解决方案

#1


1  

You should not be doing long running tasks within Apache processes, nor even waiting for them. Use a background task queueing system such as Celery to run them. Have any web request return as soon as it is queued and implement some sort of polling mechanism as necessary to see if the job is complete and results can be obtained.

您不应该在Apache进程中执行长时间运行的任务,甚至不能等待它们。使用后台任务排队系统(如Celery)来运行它们。有任何Web请求在排队后立即返回,并根据需要实施某种轮询机制,以查看作业是否完整并可以获得结果。

Also, are you sure the 504 isn't coming from some front end proxy (explicit or transparent) or load balancer? There is no default timeout in Apache which is 30 minutes.

此外,您确定504不是来自某些前端代理(显式或透明)或负载均衡器吗? Apache中没有默认超时30分钟。

#1


1  

You should not be doing long running tasks within Apache processes, nor even waiting for them. Use a background task queueing system such as Celery to run them. Have any web request return as soon as it is queued and implement some sort of polling mechanism as necessary to see if the job is complete and results can be obtained.

您不应该在Apache进程中执行长时间运行的任务,甚至不能等待它们。使用后台任务排队系统(如Celery)来运行它们。有任何Web请求在排队后立即返回,并根据需要实施某种轮询机制,以查看作业是否完整并可以获得结果。

Also, are you sure the 504 isn't coming from some front end proxy (explicit or transparent) or load balancer? There is no default timeout in Apache which is 30 minutes.

此外,您确定504不是来自某些前端代理(显式或透明)或负载均衡器吗? Apache中没有默认超时30分钟。