簡體   English   中英

在生產中顯示的錯誤消息 - Ruby on Rails 3.1,Nginx,Unicorn

[英]Error Messages Showing in Production - Ruby on Rails 3.1, Nginx, Unicorn

我有一個使用Nginx和Unicorn在生產中運行的Rails 3.1應用程序。 由於某種原因,我的自定義404和500 html錯誤頁面沒有顯示。 相反,我得到實際的錯誤消息(例如,“路由錯誤”)。

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

在具有幾乎相同配置的同一台服務器上,我有一個“暫存”網站,工作得很好。 據我所知,唯一的區別是生產者有SSL,而分期沒有。

這是生產應用程序的Nginx配置:

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指令。

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

它位於您的http偵聽器中,但不是https偵聽器。

假設Rails的force_ssl成功重定向所有http請求,並且您的唯一錯誤發生在https請求上,似乎可以解釋它。

另外,很明顯,Rack / Rails3中存在一個關於路由錯誤的眾所周知的問題,您特別提到。

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

如果你正在使用haproxy以及nginx和unicorn(例如你在Engineyard),這個修復是不夠的。 你需要重寫Rails的像這樣的東西

class ActionDispatch::Request
  def local?
    Rails.env != 'production'
  end
end

祝好運!

不確定這是否適用但我們的nginx配置中有一個鏈接在error_page行之后處理/500.html頁面的位置

location = /500.html {root / path / to / rails / app / public; }

顯然用您的路徑替換rails應用程序部分的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM