nginx中的请求超时

ocebsuys  于 2022-11-02  发布在  Nginx
关注(0)|答案(1)|浏览(319)

我在我的应用程序的服务器端得到499(在nginx上),在客户端得到504。客户端的默认超时是5000秒,而我得到的响应正好是在60秒之后。
下面是我的应用程序的nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        underscores_in_headers on;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json           
        application/javascript text/xml application/xml application/xml+rss   text/javascript;
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    }

gunicorn config为:

bind = '127.0.0.1:8001'
backlog = 2048
workers = 8
worker_class = 'sync'
worker_connections = 1000
timeout = 300
keepalive = 2
spew = False
daemon = False
pidfile = None
umask = 0
user = None
group = None
tmp_upload_dir = None
errorlog = 'gunicorn_error.log'
loglevel = 'info'
accesslog = 'gunicorn_access.log'
proc_name = None
def post_fork(server, worker):
    server.log.info("Worker spawned (pid: %s)", worker.pid)

def pre_fork(server, worker):
    pass

def pre_exec(server):
    server.log.info("Forked child, re-executing.")

def when_ready(server):
    server.log.info("Server is ready. Spawning workers")

def worker_int(worker):
    worker.log.info("worker received INT or QUIT signal")

    ## get traceback info
    import threading, sys, traceback
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,""),
            threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename,
                lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    worker.log.debug("\n".join(code))

def worker_abort(worker):
    worker.log.info("worker received SIGABRT signal")

有人能告诉我为什么会发生这种情况吗?还有我该如何纠正它。

yquaqz18

yquaqz181#

我在长时间执行命令时遇到了同样问题。我在nginx配置中为根端点使用了类似的配置来修复这个问题:

location / { 
    proxy_pass http://127.0.0.1:8001; 
    ...
    proxy_connect_timeout 5000s; 
    proxy_read_timeout 5000s; 
}

请注意proxy_connect_timeoutproxy_read_timeout
还可能有助于向用户返回一些快速响应,如“正在处理...”或“正在加载...”,并在后台运行主任务。

相关问题