【发布时间】:2019-03-10 09:28:15
【问题描述】:
在 ruby on rails 应用程序中,我有一个包含约 10,000 个条目的表,可以使用不同的参数进行搜索。在开发盒上,这工作正常,但在生产盒上,我得到一个错误。
2018/10/04 15:46:39 [error] 3418#3418: *6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.5, server: my.site.com, request: "POST /quotes/quoteTable_js HTTP/1.1", upstream: "http://unix:///path/to/app/shared/tmp/sockets/puma.awi_staging.sock/items/itemTable_js", host: "192.168.1.25", referrer: "http://192.168.1.25/items"
我没有设置服务器,所以这里有点不够深入。我查看了以下问题
- Nginx reverse proxy causing 504 Gateway Timeout
- upstream timed out (110: Connection timed out) for static content?
- NGINX: upstream timed out (110: Connection timed out) while reading response header from upstream
但是,这些都不起作用,或者我没有正确实现它们。
我的 nginx.conf 文件
user nginx;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
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;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
编辑
我在大约 7 秒后收到“我们很抱歉,但出了点问题”的 rails 消息。我尝试增加 keepalive_timeout,但没有任何改变。
【问题讨论】:
-
问题在于您的 RoR 应用程序,而不是 Nginx。尝试使用 Nginx 修复它可能会浪费时间。有关您的 RoR 应用程序的更多信息将在此处更相关(即日志,或者可能有关数据库架构和查询的详细信息)
-
您的生产应用程序很可能在集群模式下运行 Puma。这将需要更改/更新 ActiveRecord 初始化 - 特别是在分叉之前/之后关闭任何现有的数据库连接。未能管理
before_fork/after_fork回调(或on_worker_boot)可能会导致您描述的错误。
标签: ruby-on-rails nginx puma