生产中显示的错误消息-Ruby on Rails 3.1,Nginx,Unicorn [英] Error Messages Showing in Production - Ruby on Rails 3.1, Nginx, Unicorn

查看:73
本文介绍了生产中显示的错误消息-Ruby on Rails 3.1,Nginx,Unicorn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Nginx和Unicorn在生产中运行的Rails 3.1应用程序.并且由于某种原因,我的自定义404和500 html错误页面没有显示.相反,我收到了实际的错误消息(例如路由错误").

I have a Rails 3.1 app running in production using Nginx and Unicorn. And for some reason, my custom 404 and 500 html error pages are not showing. Instead I'm getting the actual error message ("Routing Error", for example).

在我的production.rb文件中,我有config.consider_all_requests_local = false

In my production.rb file, I have config.consider_all_requests_local = false

在配置几乎相同的同一台服务器上,我有一个临时"站点,该站点工作正常.据我所知,唯一的区别是生产版本具有SSL,而暂存阶段没有SSL.

And on the same server with a nearly identical configuration, I have a 'staging' site that works just fine. The only difference, as far as I can tell, is that the production one has SSL while the staging does not.

这是生产应用程序的Nginx配置:

Here is the Nginx config for the production app:

upstream unicorn_myapp_prod {
  server unix:/tmp/unicorn.myapp_prod.sock fail_timeout=0;
}

server {
  listen 80;

  server_name myapp.com;

  root /home/deployer/apps/myapp_prod/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn_myapp_prod;
  }

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


server {
  listen 443 default;
  ssl on;
  ssl_certificate /home/deployer/apps/myapp_prod/shared/ssl_certs/myapp_prod.crt;
  ssl_certificate_key /home/deployer/apps/myapp_prod/shared/ssl_certs/myapp_prod.key;


  server_name myapp.com;

  root /home/deployer/apps/myapp_prod/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn_myapp_prod;
  }

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

有什么想法吗?谢谢!

推荐答案

https侦听器的location @unicorn块缺少X-Forwarded-For指令.

The https listener's location @unicorn block is missing the X-Forwarded-For directive.

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

它在您的http侦听器中,而不在https侦听器中.

It's in your http listener, but not the https listener.

假设Rails的force_ssl成功重定向了所有http请求,而您唯一的错误发生在https请求上,那么似乎可以解释这一点.

Assuming that Rails' force_ssl is successfully redirecting all of the http requests and your only errors are happening on https requests, it seems that would explain it.

另外,非常清楚的是,Rack/Rails3中存在一个众所周知的关于路由错误的问题.

Also, to be very clear, there is a well known problem in Rack/Rails3 with respect to routing errors, which you specifically mention.

https://rails.lighthouseapp. com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror

这篇关于生产中显示的错误消息-Ruby on Rails 3.1,Nginx,Unicorn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆