gpt4 book ai didi

Django + uWSGI + nginx 请求挂起

转载 作者:行者123 更新时间:2023-12-02 06:49:25 26 4
gpt4 key购买 nike

我正在使用 Nginx 和 uWSGI 运行 Django Web 应用程序。我遇到了请求无明显原因挂起的问题。

我在应用程序中添加了一堆日志记录,而这个代码片段似乎是卡在那里的。在 try block 的开头有两行日志,第一行被打印,但第二行没有打印,所以看起来它卡在代码中间。此代码来 self 在 Django 配置中添加的中间件类。

def process_request(self, request):
if 'auth' not in request.session:
try:
log.info("Auth not found") # this line is logged
log.info("another log line") # this line is never logged
if request.is_ajax():
return HttpResponse(status=401)
...

我设法从 uWSGI 线程获取回溯,这就是它被卡住的地方:

*** backtrace of 76 ***
/usr/bin/uwsgi(uwsgi_backtrace+0x2e) [0x45121e]
/usr/bin/uwsgi(what_i_am_doing+0x30) [0x451350]
/lib/x86_64-linux-gnu/libc.so.6(+0x36c30) [0x7f8a4b2b8c30]
/lib/x86_64-linux-gnu/libc.so.6(epoll_wait+0x33) [0x7f8a4b37d653]
/home/vdr/vdr-ui/env/local/lib/python2.7/site-packages/gevent/core.so(+0x27625) [0x7f8a44092625]
/home/vdr/vdr-ui/env/local/lib/python2.7/site-packages/gevent/core.so(ev_run+0x29b) [0x7f8a4409d11b]
/home/vdr/vdr-ui/env/local/lib/python2.7/site-packages/gevent/core.so(+0x32bc0) [0x7f8a4409dbc0]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x4bd4) [0x7f8a4a0c30d4]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x80d) [0x7f8a4a0c517d]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(+0x162310) [0x7f8a4a0c5310]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7f8a4a08ce23]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(+0x7d30d) [0x7f8a49fe030d]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7f8a4a08ce23]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47) [0x7f8a4a04b837]
/home/vdr/vdr-ui/env/local/lib/python2.7/site-packages/greenlet.so(+0x375c) [0x7f8a49b1c75c]
/home/vdr/vdr-ui/env/local/lib/python2.7/site-packages/greenlet.so(+0x30a6) [0x7f8a49b1c0a6]
[0x7f8a42f26f38]
*** end of backtrace ***
SIGUSR2: --- uWSGI worker 3 (pid: 76) is managing request /login?next=/&token=45092ca6-c1a0-4c23-9d44-4d171fc561b8 since Wed Dec 2 09:52:44 2015 ---

从上游读取响应头时,Nginx 错误日志打印出[error] 619#0: *55 upper timed out (110: Connection timed out),client: 172.17.0.1, server: vdr

uWSGI 的打印输出没有错误,所以我有点不知所措。有人见过类似的东西吗?如果有什么不同的话,所有这些都在 Docker 容器内运行。

Nginx 配置:

upstream uwsgi {
server unix:///tmp/vdr.sock;
}

server {
listen 80;
charset utf-8;
client_max_body_size 500M;
server_name localhost 172.17.0.2;

location /static {
alias /home/vdr/vdr-ui/static;
}
location / {
include uwsgi_params;
uwsgi_pass uwsgi;
uwsgi_read_timeout 200s;
}
}

uWSGI session :

[uwsgi]

chdir = %d
module = alft_ui.wsgi:application
uid=1000
master=true
pidfile=/tmp/vdr.pid
vacuum=true
max-requests=5000
processes=4
env=DJANGO_SETTINGS_MODULE=alft_ui.settings.prod-live
home=/home/vdr/vdr-ui/env
socket=/tmp/vdr.sock
chmod-socket=666

最佳答案

所以我终于找到了原因。事实证明,我的安装脚本在 Django 配置中添加了一些 Logstash 设置。这些设置指向无法从此环境访问的 IP 10.8.0.1。这可以解释为什么应用程序卡在日志线上。删除这些设置使一切恢复正常。

知道这一直都是你自己的错总是很高兴:)

关于Django + uWSGI + nginx 请求挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34023882/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com