容器内监听 8080,对外经门户反代走 443。nginx 默认把重定向拼成 $scheme://$host:$server_port,于是 GET /admin(无尾斜杠)被 301 到 http://<域名>:8080/admin/:既泄漏内部端口,又把 https 降级成 http。 - absolute_redirect off + port_in_redirect off,改用相对 Location - 为 /admin /item-icons /wallpapers /extension 显式处理无尾斜杠请求
130 lines
4.7 KiB
Nginx Configuration File
130 lines
4.7 KiB
Nginx Configuration File
worker_processes auto;
|
||
pid /run/nginx.pid;
|
||
error_log /var/log/nginx/error.log warn;
|
||
|
||
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
http {
|
||
include /etc/nginx/mime.types;
|
||
default_type application/octet-stream;
|
||
sendfile on;
|
||
keepalive_timeout 65;
|
||
client_max_body_size 0;
|
||
gzip on;
|
||
gzip_types text/plain text/css application/json application/javascript text/xml;
|
||
|
||
# 全部服务通过统一 8080 端口对外
|
||
server {
|
||
listen 8080;
|
||
server_name _;
|
||
|
||
# 容器内部监听 8080,但对外是 443/80(经门户反代)。
|
||
# nginx 生成重定向时默认拼绝对地址 $scheme://$host:$server_port,
|
||
# 会把内部端口泄漏到公网(曾把 /admin 跳到 http://<域名>:8080/admin/),
|
||
# 而且 https 会被降级成 http。关掉绝对重定向,改用相对 Location。
|
||
absolute_redirect off;
|
||
port_in_redirect off;
|
||
|
||
# Dashy 静态文件
|
||
root /app/dashy;
|
||
index index.html;
|
||
|
||
# ===== SearXNG 反向代理 =====
|
||
# SearXNG 路由是 /search(无尾斜杠),/search/ 会 404,故 rewrite 去掉尾斜杠。
|
||
location ~ ^/search/?$ {
|
||
rewrite ^/search/?$ /search break;
|
||
proxy_pass http://127.0.0.1:8888;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
# SearXNG 静态资源(主题/前端脚本,页面上以 /static/... 绝对路径引用)
|
||
location /static/ {
|
||
proxy_pass http://127.0.0.1:8888;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
# 其他 SearXNG 页面/接口(结果页内的链接会引用这些根路径)
|
||
location ~ ^/(autocompleter|preferences|stats|about|donate|opensearch.xml|image_proxy|translations)/? {
|
||
proxy_pass http://127.0.0.1:8888;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
|
||
# History API(内部 3004)
|
||
location /api/history/ {
|
||
proxy_pass http://127.0.0.1:3004/;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
|
||
# Admin WebUI(内部 3005)
|
||
#
|
||
# 必须显式处理不带尾斜杠的 /admin:否则它会落到 `location /` 的
|
||
# try_files $uri/ 分支,nginx 自动补斜杠时按 $host:$server_port 拼出
|
||
# 绝对地址,于是公网被跳到 http://<域名>:8080/admin/(容器内部端口泄漏)。
|
||
# 这里返回相对地址,浏览器沿用当前的协议/主机/端口。
|
||
location = /admin {
|
||
return 301 /admin/;
|
||
}
|
||
|
||
location /admin/ {
|
||
proxy_pass http://127.0.0.1:3005/;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
|
||
# conf.yml 由 nginx 直接提供(从 data volume 读取)
|
||
location = /conf.yml {
|
||
alias /app/data/conf.yml;
|
||
}
|
||
|
||
# 可选的扩展商店链接:部署方把 extension-store.json 放进 data 卷即可,
|
||
# /extension/install.html 会读取它并显示「一键安装」按钮。
|
||
location = /extension/store.json {
|
||
alias /app/data/extension-store.json;
|
||
add_header Cache-Control "no-store";
|
||
}
|
||
|
||
# item-icons 从 data volume 提供
|
||
location = /item-icons {
|
||
return 301 /item-icons/;
|
||
}
|
||
|
||
location /item-icons/ {
|
||
alias /app/data/item-icons/;
|
||
}
|
||
|
||
# 自定义壁纸(后台「外观」上传,目录也在 data 卷)
|
||
location = /wallpapers {
|
||
return 301 /wallpapers/;
|
||
}
|
||
|
||
location /wallpapers/ {
|
||
alias /app/data/wallpapers/;
|
||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||
}
|
||
|
||
# 浏览器扩展安装包目录
|
||
location = /extension {
|
||
return 301 /extension/;
|
||
}
|
||
|
||
# Dashy SPA 路由兜底
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
}
|
||
}
|
||
}
|