简体   繁体   English

nginx + uwsgi 502 Bad Gateway python

[英]nginx + uwsgi 502 Bad Gateway python

I'm running a script in python and takes a long time to process. 我在python中运行脚本并且需要很长时间才能处理。 The thing is if the function takes to long to run, i guess the nginx has a timeout, in his configuration and that prevents somekind of errors, and prevents the function to run completely. 问题是如果函数需要很长时间才能运行,我想nginx在他的配置中有一个超时,可以防止出现一些错误,并阻止该函数完全运行。

I just want to know were i can increse the value of the timeout. 我只想知道我可以增加超时的值。 Because i've tried some commands in the file conf of nginx such as: 因为我在nginx的文件conf中尝试了一些命令,例如:

uwsgi_connect_timeout 75;
uwsgi_send_timeout 75;
uwsgi_read_timeout 75;
keepalive_timeout 650;

but none of this worked. 但这一切都没有奏效。

Thks in advance 请提前

The problem with just extending the timeout is that no matter how much longer you set it to you will run into limitations somewhere along the line. 仅仅延长超时的问题在于,无论您将其设置为多久,您都会遇到某些限制。 Either with the web server, the browser or your geocode calls. 使用Web服务器,浏览器或地理编码调用。 If it is something that routinely fails n times in a request, then you can't really make any guarantees. 如果在请求中经常失败n次,那么你就无法做出任何保证。

So rather than having the client request hanging on a long running process (and by extension risking a server timeout), why don't you use something like celery to run those geocode tasks and on the client-side, submit your client-side request via javascript and poll the server for the answer via ajax until it get's a response? 因此,不要让客户端请求挂起在长时间运行的进程上(并且通过扩展冒服务器超时),为什么不使用像celery这样的东西来运行那些地理编码任务,而在客户端,提交客户端请求通过javascript并通过ajax轮询服务器以获得答案,直到它得到响应?

I also had Bad gateway error in NGIX + uWSGI configuration, and for sake of people who google this question: it might be missing uwsgi python plugin. 我在NGIX + uWSGI配置中也有错误的网关错误,并且为了谷歌这个问题的人:它可能缺少uwsgi python插件。 Please see: uWSGI configuration issue: uwsgi fails without any error message. 请参阅: uWSGI配置问题uwsgi失败,没有任何错误消息。 .

I tried everything written in the above response as well as other places but they did not work. 我尝试了上述响应中写的所有内容以及其他地方,但它们没有用。

My solution was changing my socket in both the uwsgi.conf and nginx.conf files. 我的解决方案是在uwsgi.conf和nginx.conf文件中更改我的套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM