Skip to content
Merged
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
30 changes: 22 additions & 8 deletions nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ server {
listen 4000;
server_name localhost;

# Location 用相对路径:容器经网关反代对外服务,绝对 Location 会带上
# 容器监听端口/内部 host,跳转到不可达地址
absolute_redirect off;

root /usr/share/nginx/html;
index index.html index.htm;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
client_max_body_size 50m;

# 仅中文页面的旧根路径 URL -> /zh/ 新路径(由 scripts/gen-rewrites.mjs 生成)
include /etc/nginx/zh-only-redirects.conf;

location / {
index index.html index.htm;

root /usr/share/nginx/html;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';

client_max_body_size 50m;
# cleanUrls 平铺布局下,带尾斜杠的地址(如主站文档入口的 landing
# zh/about/overview/)既没有同名目录也没有 xxx/.html,若不回正会
# 兜底到首页 HTML,引发客户端水合错乱(首页与文档内容叠加)。
# 真实目录(/、/docs/、/docs/zh/ 等)仍按 index 正常服务,其余一律
# 301 去掉尾斜杠,回正到能命中下方 $uri.html 的干净 URL
location ~ /$ {
try_files $uri/ @cleanslash;
}
location @cleanslash {
rewrite ^(.*)/$ $1 permanent;
}

location / {
# cleanUrls: true 的产物是平铺的 xxx.html,必须尝试 $uri.html,
# 否则所有干净 URL 都会兜底到首页 HTML,引发客户端水合错乱
try_files $uri $uri.html $uri/ /docs/index.html;
Expand Down
Loading