上游过早关闭连接(uwsgi + nginx + django)

问题描述 投票:0回答:2

我正在尝试在新服务器上配置我的 Django 应用程序。除非我尝试传递 GET 参数,否则它工作正常。我收到以下错误。

uWSGI:

[pid: 21530|app: 0|req: 8/9] 109.68.173.7 () {42 vars in 880 bytes} [Thu Mar  2 17:19:29 2017] GET /install/?token=123&shop=1234&insales_id=124 => generated 0 bytes in 71 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

nginx:

2017/03/02 09:19:29 [error] 21644#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 109.68.173.7, server: 151-248-112-157.xen.vps.regruhosting.ru, request: "GET /install/?token=123&shop=1234&insales_id=124 HTTP/1.1", upstream: "uwsgi://unix:/home/trackpost.sock:", host: "151-248-112-157.xen.vps.regruhosting.ru"

我的配置文件。 nginx.conf:

    # For more information on configuration, see:                                                                                               
    #   * Official English Documentation: http://nginx.org/en/docs/                                                                             
    #   * Official Russian Documentation: http://nginx.org/ru/docs/                                                                             

    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /var/run/nginx.pid;

    # Load dynamic modules. See /usr/share/nginx/README.dynamic.                                                                                
    include /usr/share/nginx/modules/*.conf;

    events {
        worker_connections  1024;
    }


    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;

        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   120;
        client_max_body_size 20M;

        uwsgi_read_timeout 86400;
        uwsgi_send_timeout 86400;

        proxy_buffers 8 32k;
        proxy_buffer_size 64k;

        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;

        # Load modular configuration files from the /etc/nginx/conf.d directory.                                                                
        # See http://nginx.org/en/docs/ngx_core_module.html#include                                                                             
        # for more information.                                                                                                                 
        include /etc/nginx/conf.d/*.conf;

        server {
               listen 80;
               server_name 151-248-112-157.xen.vps.regruhosting.ru;
               location = favicon.ico { access_log off; log_not_found off; }
           location /static/ {
               root /home/rajansnow/django/trackpost;
           }
           location / {
              include uwsgi_params;
              uwsgi_pass unix:/home/trackpost.sock;
           }
    }
}

app.ini(uwsgi):

    [uwsgi]
project = trackpost
username = rajansnow
base = /home/%(username)/django

chdir = %(base)/%(project)
home = %(base)/venv
module = %(project).wsgi:application
plugin = python

master = true
processes = 5

uid = rajansnow
socket = /home/trackpost.sock
chown-socket = rajansnow:nginx
chmod-socket = 666
vacuum = true

touch-reload = /home/rajansnow/django/trackpost/uwsgi.ini
py-autoreload = 3
harakiri = 30

我的代码有点糟糕,我知道。但它可以在我之前的基于 Debian 的服务器上运行。当前是基于CentOS的。我已经尝试了在 SO 上找到的所有内容,但没有运气。我可以做什么来解决这个问题?

django nginx uwsgi
2个回答
1
投票

孩子们,现在是揭秘的时间了!

问题中提到的问题是通过硬检查每个项目文件解决的。事实证明,其中一些包含意外的符号,这些符号常常使 Django 抛出编码错误,从而导致 uwsgi 停止。

令人困惑的是,在问题发生之前,文件的最后一次修改已经很久了。那么它们怎么会包含额外的符号呢?没人知道。

至少现在,我们可以说它已经解决了。


0
投票

标题:

recv() failed (104: Connection reset by peer) while reading response header from upstream in Nginx

身体:

我的 Nginx 日志中遇到以下错误:

2024/08/05 17:51:54 [error] 47742#47742: *99 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.70.142.108, server: abc.xyz.com, request: "GET /ws/login/ HTTP/1.1", upstream: "http://127.0.0.1:8002/ws/login/", host: "abc.xyz.com"
2024/08/05 17:53:04 [error] 47742#47742: *112 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 162.158.170.224, server: abc.xyz.com, request: "GET /ws/login/ HTTP/1.1", upstream: "http://127.0.0.1:8002/ws/login/", host: "abc.xyz.com"

错误消息

recv() failed (104: Connection reset by peer)
表示Nginx和上游服务器(位于
http://127.0.0.1:8002/ws/login/
)之间的连接正在重置。

以下是有关我的设置的一些详细信息:

  • Nginx 配置: 服务器块设置为代理请求到
    http://127.0.0.1:8002
  • 上游服务器:它在端口 8002 上运行并处理对
    /ws/login/
    的请求。

我尝试过的事情:

  • 检查上游服务器是否有任何问题或重新启动。
  • 已验证上游服务器正在运行并且可以在端口 8002 上访问。
  • 研究了 Nginx 超时设置并根据需要进行调整。

问题:

  1. 什么可能导致上游服务器重置连接?
  2. 我应该在上游服务器上检查任何特定配置或日志来诊断此问题吗?
  3. 如何进一步排查并解决此错误?

任何指导或建议将不胜感激!


© www.soinside.com 2019 - 2024. All rights reserved.