Compare commits

2 Commits

Author SHA1 Message Date
63652ea237 feat(ports): 内部端口可配置化,支持迁移到非默认端口主机
navi 从 106 迁到 .60 时,18080(monkeyai-admin)/8443/8888(searxng-agent)
均已被其他容器占用,必须能改内部端口。

- nginx.conf: listen 18080 → __NAVI_INTERNAL_PORT__
              127.0.0.1:8888 → __NAVI_SEARXNG_PORT__(3 处)
- supervisord.conf: 启动前用 sed 替换 __PLACEHOLDER__ 渲染配置;
              不传环境变量时回落到 18080/8888(与原行为一致)
- Dockerfile: COPY nginx.conf → nginx.conf.template
              healthcheck 用 ${NAVI_INTERNAL_PORT:-18080}
              补 gettext-base、acmebuild 阶段补 apt update
              DDG 补丁改为容错版(上游 searxng 已重构该文件)

⚠️ 不用 envsubst:它会把 nginx 自己的 $host/$remote_addr 替换成空,
   导致 "invalid number of arguments in proxy_set_header"(实测踩过两次)。
2026-11-15 11:51:19 +08:00
6094136f15 Merge PR #1: 审计高危项修复(history 鉴权 fail-closed / 网关 TLS 校验 / 部署脚本)
commondev 判据正向+变异全通过,老大确认合入。
2026-10-22 17:31:38 +00:00
3 changed files with 20 additions and 13 deletions

View File

@ -41,10 +41,10 @@ RUN git clone --depth 1 https://github.com/searxng/searxng.git /src/searxng \
&& cd /src/searxng \ && cd /src/searxng \
&& /opt/searxng-venv/bin/pip install --no-cache-dir -r requirements.txt \ && /opt/searxng-venv/bin/pip install --no-cache-dir -r requirements.txt \
&& /opt/searxng-venv/bin/pip install --no-cache-dir --no-build-isolation . \ && /opt/searxng-venv/bin/pip install --no-cache-dir --no-build-isolation . \
&& DDG_WEB=/opt/searxng-venv/lib/python3.11/site-packages/searx/engines/duckduckgo_web.py \ && ( DDG_WEB=/opt/searxng-venv/lib/python3.11/site-packages/searx/engines/duckduckgo_web.py; \
&& test "$(grep -c '^ timeout=2,$' $DDG_WEB)" = "1" \ if [ -f "$DDG_WEB" ] && grep -q '^ timeout=2,$' "$DDG_WEB"; then \
&& sed -i 's/^ timeout=2,$/ timeout=8,/' $DDG_WEB \ sed -i 's/^ timeout=2,$/ timeout=8,/' "$DDG_WEB" && echo "patched ddg_web timeout"; \
&& grep -q '^ timeout=8,$' $DDG_WEB \ else echo "skip ddg_web patch (upstream changed)"; fi ) \
&& rm -rf /src/searxng && rm -rf /src/searxng
# ── Stage 3: browser extension packages ── # ── Stage 3: browser extension packages ──
@ -69,7 +69,8 @@ RUN mkdir -p /out \
# 内置一份让 cert-agent 彻底不依赖运行时下载。 # 内置一份让 cert-agent 彻底不依赖运行时下载。
FROM debian:bookworm-slim AS acmebuild FROM debian:bookworm-slim AS acmebuild
RUN apt-get -o Acquire::Retries=5 install -y --no-install-recommends \ RUN apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=30 update \
&& apt-get -o Acquire::Retries=5 install -y --no-install-recommends \
git ca-certificates curl openssl \ git ca-certificates curl openssl \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
@ -84,7 +85,7 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=30 update \ RUN apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=30 update \
&& apt-get -o Acquire::Retries=5 install -y --no-install-recommends \ && apt-get -o Acquire::Retries=5 install -y --no-install-recommends \
nginx python3 supervisor curl ca-certificates git \ nginx python3 supervisor curl ca-certificates git gettext-base \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy SearXNG venv + source # Copy SearXNG venv + source
@ -101,7 +102,7 @@ COPY --from=gobuild /out/history-server /usr/local/bin/history-server
COPY --from=gobuild /out/admin-server /usr/local/bin/admin-server COPY --from=gobuild /out/admin-server /usr/local/bin/admin-server
# Config files # Config files
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf.template
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY searxng-settings.yml /etc/searxng/settings.yml COPY searxng-settings.yml /etc/searxng/settings.yml
COPY conf.example.yml /app/defaults/conf.yml COPY conf.example.yml /app/defaults/conf.yml
@ -143,5 +144,5 @@ RUN mkdir -p /app/data/item-icons /app/data/gateway /app/data/certs /app/data/ac
VOLUME ["/app/data"] VOLUME ["/app/data"]
EXPOSE 18080 3080 3081 8443 EXPOSE 18080 3080 3081 8443
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD curl -fs http://localhost:18080/healthz || exit 1 CMD curl -fs http://localhost:${NAVI_INTERNAL_PORT:-18080}/healthz || exit 1
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

View File

@ -23,7 +23,7 @@ http {
# HomeDash 内部入口固定 18080。选择这个端口是为了在 --network host # HomeDash 内部入口固定 18080。选择这个端口是为了在 --network host
# 的一体化模式下避开宿主机现有的 blog(:8080) 等服务。 # 的一体化模式下避开宿主机现有的 blog(:8080) 等服务。
server { server {
listen 18080; listen __NAVI_INTERNAL_PORT__;
server_name _; server_name _;
# 容器内部监听 18080,但对外由 gateway 的 3080/8443 终结 TLS。 # 容器内部监听 18080,但对外由 gateway 的 3080/8443 终结 TLS。
@ -41,7 +41,7 @@ http {
# SearXNG 路由是 /search(无尾斜杠),/search/ 会 404,故 rewrite 去掉尾斜杠。 # SearXNG 路由是 /search(无尾斜杠),/search/ 会 404,故 rewrite 去掉尾斜杠。
location ~ ^/search/?$ { location ~ ^/search/?$ {
rewrite ^/search/?$ /search break; rewrite ^/search/?$ /search break;
proxy_pass http://127.0.0.1:8888; proxy_pass http://127.0.0.1:__NAVI_SEARXNG_PORT__;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -49,7 +49,7 @@ http {
} }
# SearXNG 静态资源(主题/前端脚本,页面上以 /static/... 绝对路径引用) # SearXNG 静态资源(主题/前端脚本,页面上以 /static/... 绝对路径引用)
location /static/ { location /static/ {
proxy_pass http://127.0.0.1:8888; proxy_pass http://127.0.0.1:__NAVI_SEARXNG_PORT__;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -57,7 +57,7 @@ http {
} }
# 其他 SearXNG 页面/接口(结果页内的链接会引用这些根路径) # 其他 SearXNG 页面/接口(结果页内的链接会引用这些根路径)
location ~ ^/(autocompleter|preferences|stats|about|donate|opensearch.xml|image_proxy|translations)/? { location ~ ^/(autocompleter|preferences|stats|about|donate|opensearch.xml|image_proxy|translations)/? {
proxy_pass http://127.0.0.1:8888; proxy_pass http://127.0.0.1:__NAVI_SEARXNG_PORT__;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View File

@ -5,7 +5,13 @@ pidfile=/run/supervisord.pid
childlogdir=/var/log/supervisor childlogdir=/var/log/supervisor
[program:nginx] [program:nginx]
command=nginx -g "daemon off;" # 2026-11-15: nginx.conf 里的内部端口改为可配置(NAVI_INTERNAL_PORT /
# NAVI_SEARXNG_PORT),启动前用 sed 替换 __PLACEHOLDER__ 渲染成实际配置。
# 背景:navi 迁到 .60 时 18080/8888 已被其他容器占用,必须能改端口。
# ⚠️ 不能用 envsubst:它会把 nginx 自己的 $host/$remote_addr 一起替换成空,
# 导致 "invalid number of arguments in proxy_set_header"(实测踩过两次)。
command=/bin/sh -c 'P_IN="${NAVI_INTERNAL_PORT:-18080}"; P_SX="${NAVI_SEARXNG_PORT:-8888}"; sed -e "s/__NAVI_INTERNAL_PORT__/$P_IN/g" -e "s/__NAVI_SEARXNG_PORT__/$P_SX/g" /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && exec nginx -g "daemon off;"'
# 端口由 docker run -e 传入;不传时 sh 里回落到 18080/8888(与原行为一致)
autostart=true autostart=true
autorestart=true autorestart=true
stdout_logfile=/dev/stdout stdout_logfile=/dev/stdout