Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ map $request_uri $has_no_extension {
default 0;
}

# Detect trailing slash (except root /) and capture path without it
map $request_uri $trailing_slash_uri {
~^(.+)/(\?.*)?$ $1$2;
default "";
}

server {
listen 0.0.0.0:8080;
server_name docs.apify.com docs.apify.loc;
Expand All @@ -21,6 +27,11 @@ server {
set $backend "https://apify.github.io/apify-docs";
resolver 1.1.1.1 8.8.8.8 valid=30s ipv6=off;

# redirect trailing slashes (except root /) - processed before location matching
if ($trailing_slash_uri) {
return 301 $trailing_slash_uri;
}

location = / {
if ($serve_markdown) {
rewrite ^ /llms.txt last;
Expand All @@ -34,12 +45,6 @@ server {
proxy_pass $backend$uri;
}

# remove trailing slashes from all URLs (except root /)
# exact match locations (e.g., location = /sdk/js/) take priority over this regex
location ~ ^(.+)/$ {
rewrite ^(.+)/$ $1$is_args$args? redirect;
}

location / {
set $rewrite_condition "$serve_markdown$has_no_extension";
set $proxy_path $request_uri;
Expand Down