2015-11-05 61 views
5

偶尔我的Rails应用程序可能会因为任何错误而崩溃,并且在生产时访问特定的URL时,有人可能会登录到/500.html页面。Rails 4和Nginx + Passenger的缓存问题

到目前为止一切正常。我们可以通过日志查看问题所在,然后修复。但是,为了正确查看页面,我们必须清除浏览器缓存,否则我们会再次重定向到/500.html

有没有办法阻止?

我在下面描述的示例的工作流:

  1. 导航到www.whatever.com/order/view/4444
  2. 因为在我们的数据/代码的一个问题,用户被重定向到www.whatever的.com/500.html
  3. 我们查看日志,找出问题并修复它
  4. 如果我不清除浏览器缓存,尝试导航到www.whatever.com/order/view/4444后我是重新定向到/500.html
  5. I f我清除缓存,一切正常工作

在Rails或Nginx配置中有什么我们可以做的,这样我就不必在更改Rails应用程序后清除浏览器缓存?

nginx.conf

# For more information on configuration, see: 
# * Official English Documentation: http://nginx.org/en/docs/ 
# * Official Russian Documentation: http://nginx.org/ru/docs/ 

user nginx; 
worker_processes 1; 

error_log /var/log/nginx/error.log; 
#error_log /var/log/nginx/error.log notice; 
#error_log /var/log/nginx/error.log info; 

pid  /run/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 

    #gzip on; 

    index index.html index.htm; 

    # Load modular configuration files from the /etc/nginx/conf.d directory. 
    # See http://nginx.org/en/docs/ngx_core_module.html#include 
    # for more information. 
    include /etc/nginx/conf.d/*.conf; 

    server { 
     listen  80 default_server; 
     server_name localhost; 
     root   /usr/share/nginx/html; 

     #charset koi8-r; 

     #access_log /var/log/nginx/host.access.log main; 

     # Load configuration files for the default server block. 
     include /etc/nginx/default.d/*.conf; 

     location/{ 
     } 

     # redirect server error pages to the static page /40x.html 
     # 
     error_page 404    /404.html; 
     location = /40x.html { 
     } 

     # redirect server error pages to the static page /50x.html 
     # 
     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
     } 
    } 
} 

myapp.conf

server { 
    listen 80; 
    server_name example.com www.example.com; 

    # Tell Nginx and Passenger where your app's 'public' directory is 
    root /var/www/xxx/public; 

    # Turn on Passenger 
    passenger_enabled on; 
    passenger_ruby /usr/local/rvm/gems/ruby-2.0.0-p643/wrappers/ruby; 
    passenger_friendly_error_pages on; 
} 
+0

nginx的配置文件是有什么在JavaScript是导航用户是不存在,那么另一页?或者,也许有东西会自动登录到用户然后重定向? – Kyle

+0

不,用户正常登录。我已经看到,用户被重定向的请求(重定向缓存可能?),没有任何请求到应用程序服务器。 – mentalic

+1

你可以发布你的nginx配置吗? – Kyle

回答

0

我发现的错误。我们在config/routes.rb中输入了以下内容以显示自定义错误消息。所以实际上500和422的响应代码被作为重定向处理(并因此被缓存)。

get '/500', :to => redirect('/500.html') 
get '/422', :to => redirect('/422.html') 
0

化妆SENDFILE过上像下面

http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile  off; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 

    #gzip on; 

    index index.html index.htm;