Rails4 ActionController::InvalidAuthenticityToken error

前端 未结 6 2276
醉酒成梦
醉酒成梦 2021-02-13 00:07

I have Rails4 application running in production, and my visitors run occasionally into ActionController::InvalidAuthenticityToken error, which I cant reproduce. I get 2-4 daily

6条回答
  •  醉梦人生
    2021-02-13 00:30

    I had same trouble. Server: nginx + passenger

    nginx.conf:

    http {
        ...
        expires    90d;
        ...
        server {
            server_name domain1.com
            ...
        }
        server {
            server_name domain2.com
            ...
        }
        server {
            server_name domain_3_with_rails.com
            ...
        }
    }
    

    Problems in instruction "expires 90d;" Browser locally cached page with form and with authenticity_token.

    Solution: add "expires 0d;" for rails domains:

    nginx.conf:

    http {
        ...
        expires    90d;
        ...
        server {
            server_name domain1.com
            ...
        }
        server {
            server_name domain2.com
            ...
        }
        server {
            server_name domain_3_with_rails.com
            expires 0d;
            ...
        }
    }
    

    After that, be sure to restart Nginx.

    For those who have apache: apache it certainly has a similar statement "expires" for nginx

提交回复
热议问题