Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4.0.0在现有路由中遇到定期路由错误异常(404)_Ruby On Rails_Ruby_Nginx_Puma - Fatal编程技术网

Ruby on rails Rails 4.0.0在现有路由中遇到定期路由错误异常(404)

Ruby on rails Rails 4.0.0在现有路由中遇到定期路由错误异常(404),ruby-on-rails,ruby,nginx,puma,Ruby On Rails,Ruby,Nginx,Puma,问题是,我们的站点定期为存在的路由呈现404 RoutingError异常;甚至根路径 这个问题似乎在一天中最忙的时候突然出现。如果刷新页面,页面可能会正确呈现,也可能不会 如果Puma被刷新,该问题将暂时缓解 实际存在的路由的这些404异常的puma日志与实际不存在的路由的404异常的puma日志完全相同。下面是一个日志示例: ActionController::RoutingError (No route matches [GET] : "/app" actionpack (4.0.11

问题是,我们的站点定期为存在的路由呈现404 RoutingError异常;甚至根路径

这个问题似乎在一天中最忙的时候突然出现。如果刷新页面,页面可能会正确呈现,也可能不会

如果Puma被刷新,该问题将暂时缓解

实际存在的路由的这些404异常的puma日志与实际不存在的路由的404异常的puma日志完全相同。下面是一个日志示例:

ActionController::RoutingError (No route matches [GET] : "/app"
  actionpack (4.0.11.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.11.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.11.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.11.1) lib/rails/rack/logger.rb:22:in `call'
  request_store (1.1.0) lib/request_store/middleware.rb:8:in `call'
  actionpack (4.0.11.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.5) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.11.1) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.11.1) lib/rails/engine.rb:511:in `call'
  railties (4.0.11.1) lib/rails/application.rb:97:in `call'
  puma (2.15.3) lib/puma/configuration.rb:79:in `call'
  puma (2.15.3) lib/puma/server.rb:541:in `handle_request'
  puma (2.15.3) lib/puma/server.rb:388:in `process_client'
  puma (2.15.3) lib/puma/server.rb:270:in `block in run'
  puma (2.15.3) lib/puma/thread_pool.rb:106:in `call'
  puma (2.15.3) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
此路由确实存在,但服务器仍在向请求提供404

我不知道发生了什么,所以我在下面介绍了服务器的配置

一般服务器信息

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
upstream puma {
  server unix:/tmp/puma.sock;
}

server {
  listen 80 default deferred default_server;

  root /home/deployer/deploys/current/public;

  if ($http_host ~* domain.com) {
    return 301 https://$host$request_uri$is_args$args;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    proxy_set_header X-Forwarded-Proto https;
  }

  try_files $uri/index.html $uri @puma;

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi|svg)$ {
    try_files $uri @puma;
  }

  location @puma {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header X-Forwarded-Ssl off;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 250;  #4 minutes
    proxy_pass http://puma;
    proxy_set_header X-Forwarded-Proto https;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 60;
}

server {
  listen 443 default_server ssl;
  server_name _;

  ssl                  on;
  ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
  ssl_certificate      /home/deployer/ssl/tld/domain.chained.crt;
  ssl_certificate_key  /home/deployer/ssl/tld/domain.key;

  root /home/deployer/deploys/current/public;

  if ($http_host !~* domain.com) {
    return 301 http://$host$request_uri$is_args$args;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    proxy_set_header X-Forwarded-Proto https;
  }

  try_files $uri/index.html $uri @puma;

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi|svg)$ {
    try_files $uri @puma;
  }

  location @puma {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 250;  #4 minutes
    proxy_pass http://puma;
    proxy_set_header X-Forwarded-Proto https;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 60;
}
Ubuntu 14.04

Nginx 1.4.7

美洲狮2.15.3

Ruby 2.2.0

轨道4.0.11.1

Nginx配置

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
upstream puma {
  server unix:/tmp/puma.sock;
}

server {
  listen 80 default deferred default_server;

  root /home/deployer/deploys/current/public;

  if ($http_host ~* domain.com) {
    return 301 https://$host$request_uri$is_args$args;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    proxy_set_header X-Forwarded-Proto https;
  }

  try_files $uri/index.html $uri @puma;

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi|svg)$ {
    try_files $uri @puma;
  }

  location @puma {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header X-Forwarded-Ssl off;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 250;  #4 minutes
    proxy_pass http://puma;
    proxy_set_header X-Forwarded-Proto https;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 60;
}

server {
  listen 443 default_server ssl;
  server_name _;

  ssl                  on;
  ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
  ssl_certificate      /home/deployer/ssl/tld/domain.chained.crt;
  ssl_certificate_key  /home/deployer/ssl/tld/domain.key;

  root /home/deployer/deploys/current/public;

  if ($http_host !~* domain.com) {
    return 301 http://$host$request_uri$is_args$args;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    proxy_set_header X-Forwarded-Proto https;
  }

  try_files $uri/index.html $uri @puma;

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi|svg)$ {
    try_files $uri @puma;
  }

  location @puma {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 250;  #4 minutes
    proxy_pass http://puma;
    proxy_set_header X-Forwarded-Proto https;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 60;
}
Nginx虚拟主机配置

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
upstream puma {
  server unix:/tmp/puma.sock;
}

server {
  listen 80 default deferred default_server;

  root /home/deployer/deploys/current/public;

  if ($http_host ~* domain.com) {
    return 301 https://$host$request_uri$is_args$args;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    proxy_set_header X-Forwarded-Proto https;
  }

  try_files $uri/index.html $uri @puma;

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi|svg)$ {
    try_files $uri @puma;
  }

  location @puma {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header X-Forwarded-Ssl off;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 250;  #4 minutes
    proxy_pass http://puma;
    proxy_set_header X-Forwarded-Proto https;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 60;
}

server {
  listen 443 default_server ssl;
  server_name _;

  ssl                  on;
  ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
  ssl_certificate      /home/deployer/ssl/tld/domain.chained.crt;
  ssl_certificate_key  /home/deployer/ssl/tld/domain.key;

  root /home/deployer/deploys/current/public;

  if ($http_host !~* domain.com) {
    return 301 http://$host$request_uri$is_args$args;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    proxy_set_header X-Forwarded-Proto https;
  }

  try_files $uri/index.html $uri @puma;

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi|svg)$ {
    try_files $uri @puma;
  }

  location @puma {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 250;  #4 minutes
    proxy_pass http://puma;
    proxy_set_header X-Forwarded-Proto https;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 60;
}
Puma配置(config/Puma.rb)

通过Capistrano部署Puma

exec su - deployer -c 'cd /home/deployer/deploys/releases/20160303234701; export PORT=5000; export RAILS_ENV=production;  export PUMA_WORKERS=4; bundle exec puma -e $RAILS_ENV --pidfile /tmp/puma.pid -C config/puma.rb -b unix:///tmp/puma.sock >> /var/log/domain-service/web-1.log 2>&1'

这被追踪到一个
重新加载路径呼叫管制员。

让我们看看您的路线。rb