|
| 1 | +# Map Accept headers to Markdown flag |
1 | 2 | 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 |
5 | 17 | } |
6 | 18 |
|
7 | 19 | 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; |
10 | 22 |
|
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/; |
16 | 30 | } |
17 | | - proxy_pass https://apify.github.io/apify-docs/; |
18 | | - } |
19 | 31 |
|
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 | + } |
31 | 39 |
|
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/; |
37 | 45 | } |
38 | | - proxy_pass https://apify.github.io/apify-docs/; |
39 | | - } |
40 | 46 |
|
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 | + } |
44 | 56 |
|
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; |
47 | 61 |
|
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 | + } |
52 | 67 |
|
53 | 68 | # proxies to other repositories |
54 | 69 | location /api/client/js { |
|
0 commit comments