B. *_*kba 3 django selenium nginx gunicorn digital-ocean
我有一个使用 Selenium 和 Django 的 DigitalOcean (gunicorn/nginx) 网络应用程序。
我正在尝试从 3 个网站抓取数据并将这些数据保存在数据库中,但如果该过程花费超过 60 秒,我会收到此错误
502 Bad Gateway
nginx/1.14.0 (Ubuntu)
Run Code Online (Sandbox Code Playgroud)
如何延长或禁用 nginx 的响应等待时间?
这个错误信息...
\n\n502 Bad Gateway\nnginx/1.14.0 (Ubuntu)\nRun Code Online (Sandbox Code Playgroud)\n\n...使用DigitalOcean (gunicorn/nginx) 的原因有多种。确定 502 错误的确切原因取决于您使用的 Web 服务器以及解释请求的应用程序服务器。
\n\n不良网关错误通常是由网络服务器和应用程序处理程序之间的通信故障引起的。在许多情况下,根本问题是延迟过大或超时窗口过短。
\n\n\n\n有时,502 Bad Gateway也是由错误配置的应用程序服务器引起的,当 Web 服务器理解请求并将其传递给适当的处理程序时,但两者之间发生了某种中断。
\n\nGunicorn是广泛使用的 Python WSGI 服务器之一,诊断502 Bad Gateway错误的原因主要取决于您所使用的应用程序服务器,一些常见问题如下:
\n\nGunicorn 未运行:您需要确保Gunicorn正在运行ps。为了确保Gunicorn正在运行,您必须看到类似的输出:
www-data@nginx0:/var/log/nginx$ ps aux | grep gunicorn\nwww-data 13805 0.0 1.8 52292 18460 pts/0 S 20:32 0:00 /home/www-data/test_app/bin/python /home/www-data/test_app/bin/gunicorn --error-logfile /var/log/gunicorn/errors.log -b 0.0.0.0:8080 wsgi\nwww-data 13836 0.0 1.5 52432 15392 pts/0 S 20:34 0:00 /home/www-data/test_app/bin/python /home/www-data/test_app/bin/gunicorn --error-logfile /var/log/gunicorn/errors.log -b 0.0.0.0:8080 wsgi\nRun Code Online (Sandbox Code Playgroud)Gunicorn won\xe2\x80\x99t start:有时,Gunicorn won\xe2\x80\x99t start 由于配置文件中的拼写错误或端口冲突或无法访问的日志目录或这些情况的任意组合。在这些情况下,要检查您的 Gunicorn 配置,请执行以下命令:
\n\ngunicorn --check-config [APP_MODULE]\nRun Code Online (Sandbox Code Playgroud)NGINX 配置错误:如果 Gunicorn 配置正确,则可能NGINX没有在正确的位置寻找它。在这些情况下,打开NGINX配置文件 ( /etc/nginx/nginx.conf) 并查找以upstream关键字开头的块,如下所示:
upstream app_servers {\n server 127.0.0.1:8080;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n此设置用于配置NGINX将对 _app_servers_ 的请求重定向到(在本例中)127.0.0.1:8080。如果 Gunicorn 未绑定到 127.0.0.1 或未侦听 8080,请更改 Gunicorn\xe2\x80\x99s 配置以匹配 NGINX\xe2\x80\x99s,或更改 NGINX\xe2\x80\x99s 配置以匹配 Gunicorn\ xe2\x80\x99s。此外,请验证您的站点配置是否将您的应用程序重定向到适当的上游服务器。为了确保这一点,您需要打开您的 site\xe2\x80\x99s 配置/etc/nginx/sites-enabled/your_site,即查找定义应用程序 URL 端点的块。举个例子:
location /my-app {\n proxy_pass http://app_servers;\n proxy_redirect off;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Host $server_name;\n\n}\nRun Code Online (Sandbox Code Playgroud)Gunicorn 超时:如果您的应用程序需要很长时间才能响应(默认情况下 > 30 秒),Gunicorn 可能会返回502to NGINX。这可以通过检查 Gunicorn 日志来验证(如果没有设置日志文件,则默认为 STDOUT)。举个例子,
[2016-09-21 20:33:04 +0000] [13805] [CRITICAL] WORKER TIMEOUT (pid:13810)\nRun Code Online (Sandbox Code Playgroud)\n\n上面的日志表明,应用程序响应 Gunicorn 的时间过长,导致工作线程被终止,因为 Gunicorn 认为工作线程挂起。在这种情况下,增加 Gunicorn\xe2\x80\x99s 最大执行时间将是最好的解决方案。但是,从应用程序和数据集处理的角度来看,增加超时窗口可能不是最佳解决方案,您可能需要分析和优化正在使用的应用程序。
调整read_timeout:如果修改 Gunicorn\xe2\x80\x99s 超时阈值后仍然看到502 Bad Gateway,则需要按照下面提到的这些步骤来增加超时窗口NGINX:
/etc/nginx/nginx.conf)fastcgi_read_timeout XXX;在块内添加http,其中XXX超时窗口以秒为单位(请参阅下面的示例)一个例子:
\n\nhttp { \n...\n\nfastcgi_buffers 8 16k;\nfastcgi_buffer_size 32k;\nfastcgi_connect_timeout 300;\nfastcgi_send_timeout 300;\nfastcgi_read_timeout 300;\n}\nRun Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
5896 次 |
| 最近记录: |