【问题标题】:Rails 4.2 app doesn't respond after 2-3 hours IDLE time on virtual private serverRails 4.2 应用程序在虚拟专用服务器上的 2-3 小时空闲时间后没有响应
【发布时间】:2020-09-11 16:17:40
【问题描述】:

我正在尝试在 upcloud 上设置我的虚拟专用服务器。我将 PUMA 4.3 与 ruby​​ 2.4.2 和 rails 4.2.8 一起使用。我的 Puma 配置是

threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

我的 Nginx 配置是

        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 36000s;
        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;

最后我的 example.com.conf 文件是

upstream my_app {
  server unix:///var/run/my_app.sock;
}

server {
  listen 80;
  server_name 94.237.52.251:443; # change to match your URL
  root /soop/soup; # I assume your app is located at that location

  location / {
    proxy_pass http://94.237.52.251:443; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }
}

我必须在每 15-20 分钟的空闲时间后重新启动 Rails 服务器,或者每次与 VPS 断开连接后,浏览器都会显示我 94.237.52.251 响应时间过长。 要么 目前无法处理此请求。 HTTP 错误 500 我现在面临这个问题一个星期。请帮帮我。

【问题讨论】:

  • 如果看到错误 500,请稍等一分钟左右,然后再试一次,是否还会出现此错误?
  • 我已经尝试了很多次,等了几分钟,但它没有得到修复。我每次都要重启服务器。

标签: ruby-on-rails ruby ruby-on-rails-4 puma


【解决方案1】:

将您的keepalive_timeout 36000s; 更改为 75s

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多