Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redirect paginated requests that pollute cache #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions roles/nginx/files/production/nginx/sites-available/lobste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ server {
break;
}

# /search does not use the cache, but does use ?page=N, so skip the rest
# of the rules and proxy the request.
if ($uri ~* "^/search") {
break;
}

# if there is a page parameter, rewrite it to the page path format,
# so /hottest.json?page=1 becomes /hottest/page/1.json.
# this prevents cache pollution in rails because rails cache ignores
# parameters, so /foo.json?page=10 will overwite the cache for /foo.json
# NB This redirect drops any other parameters. There may be other
# ways to pollute the cache but this is the most common.
if ($arg_page) {
rewrite "^(.*?)([.][^.?/]*)?$" $1/page/$arg_page$2? redirect;
}

# file-based full-page caching, bypass if user has cookies
set $use_file_cache "";
if ($cookie_lobster_trap = "") {
Expand Down