概要

フル名
docker.io/xscys/nginx-sidecar-basic-auth
Registry
docker.io
名前空間
xscys
リポジトリ
nginx-sidecar-basic-auth
キャッシュ Tag 数
1
最終同期
07/06/2026, 11:24 AM

概要

xscys nginx-sidecar-basic-auth 侧车镜像,为 Pod 内应用提供 Basic Auth 反向代理,适合内网微服务快速加一层访问控制。

詳細

xscys/nginx-sidecar-basic-auth 预配置 Nginx 与 htpasswd,将流量代理至同 Pod localhost 的应用端口并强制 Basic 认证。典型作为 K8s sidecar 或 Compose 双容器栈,与 Ingress Basic Auth 相比更贴近应用 Pod。定位为 sidecar 反向代理,需挂载 htpasswd 或环境变量注入凭据;K8s 场景与主容器共享 network namespace。

快速启动

docker run -d --name nginx-sidecar \
  -p 8080:80 \
  -e UPSTREAM=http://127.0.0.1:3000 \
  -e AUTH_USER=admin -e AUTH_PASS=secret \
  docker.io/xscys/nginx-sidecar-basic-auth:latest

推荐实践

docker run -d --name nginx-sidecar \
  --restart unless-stopped \
  -p 8080:80 \
  -e UPSTREAM=http://127.0.0.1:3000 \
  -v /opt/sidecar/htpasswd:/etc/nginx/htpasswd:ro \
  docker.io/xscys/nginx-sidecar-basic-auth:1.0.0

核心参数说明

  • -p 8080:80 — 对外暴露的认证入口
  • -e UPSTREAM — 后端应用地址(同 Pod 用 127.0.0.1)
  • -v .../htpasswd:... — Basic Auth 用户文件(高敏
  • --restart unless-stopped — sidecar 与主容器同生命周期
  • 固定 tag — Nginx 与 auth 模块 pin

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-with-auth-sidecar
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: app
          image: myapp:1.0.0
          ports:
            - containerPort: 3000
        - name: auth-sidecar
          image: docker.io/xscys/nginx-sidecar-basic-auth:1.0.0
          ports:
            - containerPort: 80
          env:
            - name: UPSTREAM
              value: "http://127.0.0.1:3000"
          volumeMounts:
            - name: htpasswd
              mountPath: /etc/nginx/htpasswd
              subPath: htpasswd
              readOnly: true
      volumes:
        - name: htpasswd
          secret:
            secretName: sidecar-basic-auth
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 80

Service 指向 sidecar 80 端口;Secret 轮换 htpasswd 后 rolling restart。

Tagアーキテクチャプッシュ日時サイズDigest同期期望操作
docker.io/xscys/nginx-sidecar-basic-auth
:latest
linux/amd64
2019/07/24 23:1011.6 MBsha256:a5cfdba42586