Rails 4.2应用在虚拟专用服务器上闲置2-3小时后没有响应

问题描述 投票:1回答:1

我正在尝试在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分钟的空闲时间后或在每次与VPS断开连接后重新启动Rails服务器,否则浏览器向我显示94.237.52.251花了很长时间才回应。要么当前无法处理此请求。 HTTP错误500我现在面对这个问题已有一个星期了。请帮助我。

ruby-on-rails ruby ruby-on-rails-4 puma
1个回答
0
投票

keepalive_timeout 36000s;更改为75s

© www.soinside.com 2019 - 2024. All rights reserved.