Skip to content

Commit b7eebba

Browse files
committed
fix: rewrite nginx config to support production GH pages URLs
Related: #1997
1 parent 3a33357 commit b7eebba

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

nginx.conf

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,69 @@
1+
# Map Accept headers to Markdown flag
12
map $http_accept $wants_markdown {
2-
default 0;
3-
"~*text/markdown" 1;
4-
"~*text/plain" 1;
3+
default 0;
4+
"~*text/markdown" 1;
5+
"~*text/plain" 1;
6+
}
7+
8+
# Define named upstream for local dev
9+
upstream local_docs {
10+
server 127.0.0.1:3000;
11+
}
12+
13+
# Map host to upstream
14+
map $host $docs_upstream {
15+
"docs.apify.com" https://apify.github.io/apify-docs; # production
16+
default http://local_docs; # local dev
517
}
618

719
server {
8-
listen 0.0.0.0:8080;
9-
server_name 'docs.apify.com';
20+
listen 0.0.0.0:8080;
21+
server_name docs.apify.loc docs.apify.com;
1022

11-
# homepage: only rewrite to internal proxy when client wants markdown
12-
location = / {
13-
if ($wants_markdown) {
14-
# use 'last' to force a new location lookup so /__proxy/ handler runs
15-
rewrite ^ /__proxy/llms.txt last;
23+
# Homepage: llms.txt fallback
24+
location = / {
25+
if ($wants_markdown) {
26+
rewrite ^ /__proxy/llms.txt last;
27+
}
28+
proxy_pass $docs_upstream;
29+
proxy_redirect https://apify.github.io/ https://apify.github.io/apify-docs/;
1630
}
17-
proxy_pass https://apify.github.io/apify-docs/;
18-
}
1931

20-
# direct llms.txt files, serve with markdown content type
21-
location /llms.txt {
22-
proxy_pass https://apify.github.io/apify-docs/llms.txt;
23-
proxy_hide_header Content-Type;
24-
add_header Content-Type "text/markdown; charset=utf-8" always;
25-
}
26-
location /llms-full.txt {
27-
proxy_pass https://apify.github.io/apify-docs/llms-full.txt;
28-
proxy_hide_header Content-Type;
29-
add_header Content-Type "text/markdown; charset=utf-8" always;
30-
}
32+
# Direct llms.txt files
33+
location = /llms.txt {
34+
proxy_pass $docs_upstream/llms.txt;
35+
proxy_hide_header Content-Type;
36+
add_header Content-Type "text/markdown; charset=utf-8" always;
37+
proxy_redirect https://apify.github.io/ https://apify.github.io/apify-docs/;
38+
}
3139

32-
# generic docs fallback: rewrite clean URLs to .md when client wants markdown
33-
location / {
34-
if ($wants_markdown) {
35-
# rewrite to internal proxy path; use last so new location is matched
36-
rewrite ^(/[^.]+)$ /__proxy$1.md last;
40+
location = /llms-full.txt {
41+
proxy_pass $docs_upstream/llms-full.txt;
42+
proxy_hide_header Content-Type;
43+
add_header Content-Type "text/markdown; charset=utf-8" always;
44+
proxy_redirect https://apify.github.io/ https://apify.github.io/apify-docs/;
3745
}
38-
proxy_pass https://apify.github.io/apify-docs/;
39-
}
4046

41-
# internal proxy handler that actually forces the markdown header
42-
location ^~ /__proxy/ {
43-
internal;
47+
# Generic Markdown fallback
48+
location / {
49+
if ($wants_markdown) {
50+
rewrite ^(/.*\.md)$ /__proxy$1 last;
51+
rewrite ^(/[^./]+)/*$ /__proxy$1.md last;
52+
}
53+
proxy_pass $docs_upstream;
54+
proxy_redirect https://apify.github.io/ https://apify.github.io/apify-docs/;
55+
}
4456

45-
# strip the /__proxy prefix so upstream sees the real path
46-
rewrite ^/__proxy(/.*)$ $1 break;
57+
# Internal proxy for Markdown handling
58+
location ^~ /__proxy/ {
59+
internal;
60+
rewrite ^/__proxy/(.*)$ /$1 break;
4761

48-
proxy_pass https://apify.github.io/apify-docs/;
49-
proxy_hide_header Content-Type;
50-
add_header Content-Type "text/markdown; charset=utf-8" always;
51-
}
62+
proxy_pass $docs_upstream;
63+
proxy_hide_header Content-Type;
64+
add_header Content-Type "text/markdown; charset=utf-8" always;
65+
proxy_redirect https://apify.github.io/ https://apify.github.io/apify-docs/;
66+
}
5267

5368
# proxies to other repositories
5469
location /api/client/js {

0 commit comments

Comments
 (0)