gpt4 book ai didi

database - TCP 代理到 postgres 数据库作为 nginx 中的上游服务器

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:59 24 4
gpt4 key购买 nike

问题:是否可以将Nginx设置为数据库的反向代理?这些是我目前拥有的标志,我相信拥有 --with-stream 模块足以将 TCP 流用于数据库。这是附加功能吗?

Nginx 配置选项:

--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=%{_libdir}/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' --with-ipv6

Nginx 配置

stream {

include conf.d/streams/*.conf;
}

conf.d/streams/upstream.conf的内容

upstream database_server {
least_conn;
keepalive 512;
server 192.168.99.103:32778 max_fails=5 fail_timeout=30s weight=1;

}

来自 Nginx 的错误消息

2016/02/22 03:54:13 [emerg] 242#242: invalid host in upstream "http://database_server" in /etc/nginx/conf.d/streams/database_server.conf:9

最佳答案

这是一个对我有用的 nginx 配置(我正在运行 inside Docker ,所以其中一些选项可以帮助解决这个问题):

worker_processes auto;

daemon off;

error_log stderr info;

events {
worker_connections 1024;
}

stream {
upstream postgres {
server my_postgres:5432;
}

server {
listen 5432 so_keepalive=on;
proxy_pass postgres;
}
}

对我来说关键是行 listen 5432 so_keepalive=on;,它打开 TCP keepalive。没有它,我可以连接,但我的连接会在几秒钟后重置。

关于database - TCP 代理到 postgres 数据库作为 nginx 中的上游服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35545648/

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