在我的生產服務器上使用Rails,Passenger(都是3.0.5)和Nginx。據我所知,Rails應該顯示public/404.html
或public/500.html
,而不是像ActiveRecord::RecordNotFound
或Unknown action
這樣的開發錯誤,但這並未發生。我嘗試刪除config.ru文件,並在nginx.conf中設置rack_env或rails_env,但沒有任何幫助。Rails 3 - 生產模式下的開發錯誤
這裏是我的nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /home/makk/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.5;
passenger_ruby /home/makk/.rvm/bin/passenger_ruby;
#passenger_ruby /home/makk/.rvm/wrappers/ruby-1.9.2-p0/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location/{
root /home/makk/projects/1server/deploy/current/public;
index index.html index.htm;
passenger_enabled on;
rack_env production;
recursive_error_pages on;
if (-f /home/makk/projects/1server/maintenance.html) {
return 503;
}
error_page 404 /404.html;
error_page 500 502 504 /500.html;
error_page 503 @503;
}
location @503 {
error_page 405 = /maintenance.html;
# Serve static assets if found.
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /maintenance.html break;
}
location ~ ^(\/phpmyadmin\/)(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(\/phpmyadmin\/)(.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$fastcgi_path_info;
include fastcgi_params;
}
}
}
看來,這個問題重複this one,但沒有工作的建議。
UPD:我在同一臺PC上都有開發和生產應用程序。在生產中,由於local_request?
方法的原因,Rails忽略config.consider_all_requests_local = false
(在/config/environments/production.rb中)。所以,可能的解決方案之一如下(從here拍攝):
# config/initializers/local_request_override.rb
module CustomRescue
def local_request?
return false if Rails.env.production? || Rails.env.staging?
super
end
end
ActionController::Base.class_eval do
include CustomRescue
end
或者爲Rails 3:
class ActionDispatch::Request
def local?
false
end
end
幾乎看我的問題,但沒有幫助。請參閱更新的nginx.conf。 – sunki
你的rails「public」目錄中是否有500.html和404.html? – Brandon
當然可以...... – sunki