Set fastcgi_cache_key using original $request_uri without $args

前端 未结 1 1785
[愿得一人]
[愿得一人] 2021-01-22 18:11

I am trying to integrate a WordPress plugin (Jetpack\'s Related Posts module) which adds query strings to the end of post URLs. I would like to cache URLs with FastCGI while com

1条回答
  •  孤城傲影
    2021-01-22 18:40

    Just now, I had similar problem. So, my solution:

    In the nginx config add to the

    http  { 
        ...
        map $request_uri $request_path { 
           ~(?[^?]*) $captured_path; 
        }
        ...
    }
    

    Then you will have a variable $request_path, which contains $request_uri without query_string.

    So use $request_path for cache key

    fastcgi_cache_key "$scheme$request_method$host$request_path"
    

    Important. The "map" directive can be added only to "http {}". This directive will be execute for all requests for all hosts.

    0 讨论(0)
提交回复
热议问题