Ruby on rails 在生产中显示错误消息-RubyonRails3.1、Nginx、Unicorn
我有一个Rails 3.1应用程序正在使用Nginx和Unicorn进行生产运行。由于某些原因,我的自定义404和500 html错误页面没有显示。例如,我得到的是实际的错误消息路由错误 在我的production.rb文件中,我有config.consude\u all\u requests\u local=false 在配置几乎相同的同一台服务器上,我有一个工作正常的“暂存”站点。据我所知,唯一的区别是,生产平台有SSL,而临时平台没有 以下是生产应用程序的Nginx配置:Ruby on rails 在生产中显示错误消息-RubyonRails3.1、Nginx、Unicorn,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,nginx,unicorn,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,Nginx,Unicorn,我有一个Rails 3.1应用程序正在使用Nginx和Unicorn进行生产运行。由于某些原因,我的自定义404和500 html错误页面没有显示。例如,我得到的是实际的错误消息路由错误 在我的production.rb文件中,我有config.consude\u all\u requests\u local=false 在配置几乎相同的同一台服务器上,我有一个工作正常的“暂存”站点。据我所知,唯一的区别是,生产平台有SSL,而临时平台没有 以下是生产应用程序的Nginx配置: upstream
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侦听器的位置@unicorn块缺少X-Forwarded-For指令
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
它位于http侦听器中,但不在https侦听器中
假设Rails的force_ssl成功地重定向了所有http请求,并且您唯一的错误发生在https请求上,这似乎可以解释这一点
另外,非常清楚的是,机架/导轨3中有一个众所周知的布线错误问题,您特别提到了这个问题
https侦听器的位置@unicorn块缺少X-Forwarded-For指令
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
它位于http侦听器中,但不在https侦听器中
假设Rails的force_ssl成功地重定向了所有http请求,并且您唯一的错误发生在https请求上,这似乎可以解释这一点
另外,非常清楚的是,机架/导轨3中有一个众所周知的布线错误问题,您特别提到了这个问题
不确定这是否适用,但在错误页面行之后的nginx配置中也有一个链接,用于处理/500.html页面的位置 location=/500.html{root/path/to/rails/app/public;}
显然,用您的路径替换rails应用程序部分的路径 不确定这是否适用,但在错误页面行之后的nginx配置中也有一个链接,用于处理/500.html页面的位置 location=/500.html{root/path/to/rails/app/public;}
显然,用您的路径替换rails应用程序部分的路径 如果您将haproxy与nginx和unicorn一起使用,例如,您在Engineyard上,此修复程序将不够。您需要使用以下内容覆盖Rails:
class ActionDispatch::Request
def local?
Rails.env != 'production'
end
end
祝你好运 如果您将haproxy与nginx和unicorn一起使用,例如,您在Engineyard上,此修复程序将不够。您需要使用以下内容覆盖Rails:
class ActionDispatch::Request
def local?
Rails.env != 'production'
end
end
祝你好运 您是否确保使用选项-E production启动生产站点的Unicorn进程,例如$APP_ROOT/bin/Unicorn-D-c$APP_ROOT/config/Unicorn.rb-E production?是的,该应用肯定在生产模式下运行。您是否在production.rb文件中指定了config.force_ssl=true?是的,我的production.rb中有这个选项,SSL似乎工作正常。您是否确保使用选项-E production启动生产站点的Unicorn流程,例如$APP_ROOT/bin/Unicorn-D-c$APP_ROOT/config/Unicorn.rb-E production?是的,该应用程序肯定是在生产模式下运行的。您是否在production.rb文件中指定了config.force_ssl=true?是的,我在production.rb中有这个选项,ssl似乎工作正常。使用$proxy_add_x_forwarded_for会给我重定向错误,但使用$scheme可以工作。谢谢使用$proxy\u add\u x\u forwarded\u for会导致重定向错误,但使用$scheme有效。谢谢