ubuntu - 使用 NGINX 作为 Postgres 代理的超时问题

标签 ubuntu nginx proxy

我正在设置一个代理服务器来拦截所有流量并将其转发到我的 Postgres 数据库。我正在使用 NGINX 1.19.2 来完成此任务。

我遇到的问题是任何运行时间超过 10 分钟的查询都会超时。所有较短的查询似乎都运行得很好。

这是我的整个 nginx.conf:

worker_processes auto;
pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*.conf;

events {
  worker_connections 768;
}

stream {
  server {
    # Allow up to 30s to establish a connection with the proxied database
    proxy_connect_timeout 30s;

    proxy_socket_keepalive on;

    listen 5432;
    proxy_pass my-server.rds.amazonaws.com:5432;
  }
}

我已经尝试了几个与 NGINX 代理相关的配置选项(例如 proxy_read_timeout),但是,这些选项在 stream { } 上下文中不起作用,并且需要在 http { } 上下文中。为了连接到 Postgres,我不能使用 http。

  • 有谁知道我可以做些什么来消除 NGINX 流/代理的 10 分钟连接超时?
  • 有谁知道使用 NGINX 以外的东西来完成我正在尝试做的事情的更好替代方法吗?
    • 我在 Ubuntu 上尝试了 simpleproxy,但在 2 小时后超时(是的,我们必须支持一些长时间运行的查询,例如对十亿行以上的表的 VACUUM 操作)

最佳答案

您是否在 /var/log/nginx/error.log 中看到与这些请求相关的任何错误?

如果您看到 Connection reset by peer 这意味着您的上游 (Postgres) 正在关闭连接,而不是 Nginx。

还有,你确定不是你的下游?您是直接连接到此服务器还是有负载平衡器 -> Nginx -> Postgres?负载均衡器可能正在终止连接。

我会尝试将所有超时设置设置得高得离谱,它们会进入 server {} 上下文

proxy_cache_lock_timeout
proxy_connect_timeout
proxy_next_upstream_timeout
proxy_read_timeout
proxy_send_timeout

client_body_timeout
client_header_timeout
keepalive_timeout
lingering_timeout
resolver_timeout
send_timeout

# Not sure if you're using fastcgi
fastcgi_cache_lock_timeout
fastcgi_connect_timeout
fastcgi_next_upstream_timeout
fastcgi_read_timeout
fastcgi_send_timeout

请参阅文档以了解每个内容:

对于 VACUUM 之类的事情,连接可能会终止,但进程可能仍在运行。您可以在 Postgres 中检查正在运行的进程以确认它何时完成。

关于ubuntu - 使用 NGINX 作为 Postgres 代理的超时问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63929218/

相关文章:

Mongodb 无法启动 : addr already in use

c - 如何在C中将客户端请求的数据时间和数据大小发送给客户端?

git lfs pull in repository 产生关于 dial tcp 的错误

android - SherlockActionBar : Export signed apk, 然后 Eclipse 崩溃:(

mongodb错误。如何解决 mongoDB 中的错误?

Azure 文件共享所有者/组权限在 VM 重新启动时恢复

Django 错误 : Invalid HTTP_HOST header: u'/run/myprojectname/gunicorn. socks :'

php - 高分辨率图像上传失败 stream_copy_to_stream() : read of 8192 bytes

php - Nginx,PHP-FPM,PHP Module and MySQL Implementation is possible in Kubernetes

python - 使用远程机器(类似于代理)通过 JupyterLab 打开网站