gpt4 book ai didi

ruby-on-rails - Rails 4 和 Nginx + 乘客的缓存问题

转载 作者:行者123 更新时间:2023-12-03 17:17:45 24 4
gpt4 key购买 nike

有时,我的 Rails 应用程序可能会因为任何错误而崩溃,并且在生产中访问特定 URL 时,有人可能会登陆/500.html 页面。

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

反正有什么可以防止的吗?

我在下面描述了一个示例工作流程:

  • 导航到 www.whatever.com/order/view/4444
  • 由于我们的数据/代码中的问题,用户被重定向到 www.whatever.com/500.html
  • 我们查看日志,找出问题并修复它
  • 如果我不清除浏览器缓存,在尝试导航到 www.whatever.com/order/view/4444 后,我将再次重定向到/500.html
  • 如果我清除缓存,一切正常

  • 我们可以在 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;
    }

    最佳答案

    在 nginx 配置文件上关闭 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;

    关于ruby-on-rails - Rails 4 和 Nginx + 乘客的缓存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33552927/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com