我有一個使用Nginx和Unicorn生產的Rails 3.1應用程序。由於某些原因,我的自定義404和500 html錯誤頁面未顯示。相反,我得到了實際的錯誤信息(例如「路由錯誤」)。顯示在生產中的錯誤消息 - Ruby on Rails 3.1,Nginx,Unicorn
在我production.rb文件,我有config.consider_all_requests_local = false
並配有幾乎相同的配置在同一臺服務器上,我有一個「臨時」的網站,工作得很好。據我所知,唯一的區別是生產者具有SSL,而分段則不具有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;
}
任何想法?謝謝!
您是否確定使用選項'-E production'開始生產站點的Unicorn進程,如在$ APP_ROOT/bin/unicorn -D -c $ APP_ROOT/config/unicorn.rb -E production中爲例? – emrass
是的,該應用程序肯定是在生產模式下運行。 –
您是否在'production.rb'文件中指定了'config.force_ssl = true'? – Jef