Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Commit f9c9fef

Browse files
authored
Update Dockerfile
1 parent c7fc665 commit f9c9fef

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

Dockerfile

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FROM nginx:alpine
22
RUN apk add --no-cache curl
33
RUN rm /etc/nginx/conf.d/default.conf
44

5-
# This heredoc syntax is correct for Dockerfiles
65
COPY <<EOF /etc/nginx/conf.d/gitbook-proxy.conf
76
upstream gitbook {
87
server nebulaclient.gitbook.io:443;
@@ -15,35 +14,27 @@ server {
1514
resolver 8.8.8.8 valid=300s;
1615
resolver_timeout 5s;
1716

18-
# --- START: TARGETED FIX ---
19-
# This block specifically targets sitemap.xml and robots.txt IN ANY DIRECTORY.
20-
# The regex now correctly matches paths that END WITH sitemap.xml or robots.txt.
21-
location ~ /(sitemap\.xml|robots\.txt|sitemap-pages\.xml)$ {
17+
location = /robots.txt {
18+
rewrite ^ /nebula/robots.txt last;
19+
}
20+
21+
location ~ /(sitemap\.xml|robots\.txt)$ {
2222
proxy_pass https://nebulaclient.gitbook.io;
2323
proxy_ssl_server_name on;
2424
proxy_ssl_verify off;
2525

26-
# THE FIX: Request uncompressed content from the upstream
27-
# so that sub_filter can read and modify it.
2826
proxy_set_header Accept-Encoding "";
2927

30-
# Necessary proxy headers for the request to succeed
3128
proxy_set_header Host nebulaclient.gitbook.io;
3229
proxy_set_header X-Real-IP \$remote_addr;
3330
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
3431
proxy_set_header X-Forwarded-Proto https;
3532

36-
# Perform the URL substitution on the plain text/xml content
3733
sub_filter_once off;
3834
sub_filter_types text/xml application/xml text/plain;
3935
sub_filter 'https://nebulaclient.gitbook.io' 'https://\$host';
4036
}
41-
# --- END: TARGETED FIX ---
42-
43-
44-
# --- YOUR ORIGINAL CONFIGURATION (UNCHANGED) ---
4537

46-
# Handle GitBook API calls that might contain URLs
4738
location ~* \.(json|js|txt|xml)$ {
4839
proxy_pass https://nebulaclient.gitbook.io;
4940
proxy_ssl_server_name on;
@@ -56,7 +47,6 @@ server {
5647
proxy_set_header X-Forwarded-Host \$host;
5748
proxy_set_header User-Agent \$http_user_agent;
5849

59-
# More aggressive filtering for API responses
6050
sub_filter_once off;
6151
sub_filter_types application/xml application/json application/javascript text/javascript text/plain;
6252
sub_filter 'https://nebulaclient.gitbook.io' 'https://\$host';
@@ -81,7 +71,6 @@ server {
8171
proxy_set_header X-Forwarded-Port \$server_port;
8272
proxy_set_header User-Agent \$http_user_agent;
8373

84-
# More comprehensive redirect handling
8574
proxy_redirect https://nebulaclient.gitbook.io/ https://\$host/;
8675
proxy_redirect https://nebulaclient.gitbook.io https://\$host;
8776
proxy_redirect http://nebulaclient.gitbook.io/ https://\$host/;
@@ -95,11 +84,9 @@ server {
9584
proxy_http_version 1.1;
9685
proxy_set_header Connection "";
9786

98-
# Enhanced content filtering for all content types
9987
sub_filter_once off;
10088
sub_filter_types application/xml text/plain text/html text/css text/javascript application/javascript application/json text/xml application/xml;
10189

102-
# Replace various URL patterns
10390
sub_filter 'https://nebulaclient.gitbook.io' 'https://\$host';
10491
sub_filter 'http://nebulaclient.gitbook.io' 'https://\$host';
10592
sub_filter 'nebulaclient.gitbook.io' '\$host';
@@ -109,7 +96,6 @@ server {
10996
sub_filter "http:\\/\\/nebulaclient.gitbook.io" "https:\\/\\/\$host";
11097
sub_filter "nebulaclient\\.gitbook\\.io" "\$host";
11198

112-
# Handle GitBook specific redirects
11399
proxy_intercept_errors on;
114100
error_page 301 302 307 = @handle_redirect;
115101
}
@@ -118,18 +104,16 @@ server {
118104
set \$redirect_location \$upstream_http_location;
119105
set \$redirect_host '';
120106

121-
# Extract the path from the redirect location
122107
if (\$redirect_location ~ "^https?://nebulaclient\.gitbook\.io(.*)") {
123108
set \$redirect_path \$1;
124109
return 302 https://\$host\$redirect_path;
125110
}
126111

127-
# Fallback for other redirects
128112
return 302 https://\$host/;
129113
}
130114

131115
access_log /var/log/nginx/access.log;
132-
error_log /var/log/nginx/error.log debug;
116+
error_log /var/log/nginx/error.log;
133117
}
134118
EOF
135119

0 commit comments

Comments
 (0)