Back to Skills

configure-reverse-proxy

pjt222
Updated 6 days ago
20 views
17
2
17
View on GitHub
Documentationgeneral

About

This skill configures reverse proxy setups for Nginx, Traefik, and ShinyProxy to route multiple services through a single entry point. It handles WebSocket proxying, path/host-based routing, SSL termination, and Docker label auto-discovery. Use it when exposing containerized services, managing WebSocket connections, or adding TLS to services without native SSL support.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/configure-reverse-proxy

Copy and paste this command in Claude Code to install this skill

Documentation

配反代

以 Nginx、Traefik 或 ShinyProxy 設反代路流至後端。

  • 多服於單入點後
  • 代 WebSocket 連(Shiny、Socket.IO、live reload)
  • 以 Traefik 標自發 Docker 服
  • 依路徑或主機路至異後
  • 無 TLS 本能之服加 SSL 終

  • :所代後端(host:port)
  • :路策(路徑、主機、俱)
  • :代具好(Nginx、Traefik)
  • :主機路之域名
  • :所代 WebSocket 端

一:擇代具

FeatureNginxTraefik
ConfigurationStatic filesDocker labels / dynamic
Auto-discoveryNo (manual)Yes (Docker provider)
Let's EncryptVia certbotBuilt-in ACME
DashboardNo (3rd party)Built-in
WebSocketManual configAutomatic
Best forStatic config, high trafficDynamic Docker environments

二:Nginx——路徑路

server {
    listen 80;

    location /api/ {
        proxy_pass http://api:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /app/ {
        proxy_pass http://webapp:3000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location / {
        root /usr/share/nginx/html;
        try_files $uri $uri/ /index.html;
    }
}

注: proxy_pass/ 削 location 前綴。proxy_pass http://api:8000/;location /api//api/users 轉為 /users

三:Nginx——主機路

server {
    listen 80;
    server_name api.example.com;

    location / {
        proxy_pass http://api:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://webapp:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

四:Nginx——WebSocket 代

WebSocket 須升級頭。Shiny、Socket.IO、live reload 必:

location /ws/ {
    proxy_pass http://app:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_read_timeout 86400;
}

Shiny 專用:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    location / {
        proxy_pass http://shiny:3838;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_read_timeout 86400;
        proxy_buffering off;
    }
}

得: WebSocket 連建且持。

敗:proxy_http_version 1.1 已設。驗 UpgradeConnection 頭。

五:Traefik——Docker 標自發

docker-compose.yml

services:
  traefik:
    image: traefik:v3.2
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "[email protected]"
      - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
      - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - letsencrypt:/letsencrypt

  api:
    image: myapi:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`api.example.com`)"
      - "traefik.http.routers.api.entrypoints=websecure"
      - "traefik.http.routers.api.tls.certresolver=letsencrypt"
      - "traefik.http.services.api.loadbalancer.server.port=8000"

  webapp:
    image: myapp:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.webapp.rule=Host(`app.example.com`)"
      - "traefik.http.routers.webapp.entrypoints=websecure"
      - "traefik.http.routers.webapp.tls.certresolver=letsencrypt"
      - "traefik.http.services.webapp.loadbalancer.server.port=3000"

volumes:
  letsencrypt:

得: Traefik 經標自發服、備 SSL 證。

六:Traefik——含標之路徑路

services:
  api:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`example.com`) && PathPrefix(`/api`)"
      - "traefik.http.routers.api.middlewares=strip-api"
      - "traefik.http.middlewares.strip-api.stripprefix.prefixes=/api"
      - "traefik.http.services.api.loadbalancer.server.port=8000"

七:Traefik——限率與頭

labels:
  - "traefik.http.middlewares.ratelimit.ratelimit.average=100"
  - "traefik.http.middlewares.ratelimit.ratelimit.burst=50"
  - "traefik.http.middlewares.security.headers.stsSeconds=63072000"
  - "traefik.http.middlewares.security.headers.contentTypeNosniff=true"
  - "traefik.http.middlewares.security.headers.frameDeny=true"
  - "traefik.http.routers.app.middlewares=ratelimit,security"

八:驗代配

# Nginx: test config
docker compose exec nginx nginx -t

# Check routing
curl -H "Host: api.example.com" http://localhost/health

# Check WebSocket (needs wscat: npm install -g wscat)
wscat -c ws://localhost/ws/

# Traefik dashboard (if enabled)
# http://localhost:8080/dashboard/

得: 求路至正後端。WebSocket 升成。

  • HTTP 求依路徑或主機路至正後端
  • WebSocket 連建且持
  • SSL 終行(若配)
  • 後端收正 HostX-Real-IPX-Forwarded-For
  • Traefik 經標自發新服(若用)
  • 配於 docker compose restart 後留

  • 尾斜線不合proxy_pass http://app/ vs http://app 於 Nginx 路徑削行異。
  • WebSocket 超時:默 proxy_read_timeout 60s。長連 WebSocket 須 86400(24h)。
  • Docker socket 安:於 Traefik 掛 /var/run/docker.sock 予其全 Docker 取。用 ro 掛且慮 socket 代。
  • DNS 解:Nginx 啟時解上游。動服→用 resolver 127.0.0.11 以 Docker 內 DNS。
  • proxy_buffering off:Shiny 與 SSE 端須 proxy_buffering off 以即時流。

  • configure-nginx - Nginx 詳配含 SSL 與安頭
  • deploy-shinyproxy - 容器 Shiny 應託 ShinyProxy
  • setup-compose-stack - 用反代之 compose 堆
  • configure-api-gateway - Kong 與 Traefik API 閘模

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan-ultra/skills/configure-reverse-proxy
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

railway-docs

Documentation

This skill fetches current Railway documentation to answer questions about features, functionality, or specific docs URLs. It ensures developers receive accurate, up-to-date information directly from Railway's official sources. Use it when users ask how Railway works or reference Railway documentation.

View skill

n8n-code-python

Documentation

This Claude Skill provides expert guidance for writing Python code in n8n's Code nodes, specifically for using Python's standard library and working with n8n's special syntax like `_input`, `_json`, and `_node`. It helps developers understand Python's limitations within n8n and recommends using JavaScript for most workflows while offering Python solutions for specific data transformation needs.

View skill

archon

Documentation

The Archon skill provides RAG-powered semantic search and project management through a REST API. Use it for querying documentation, managing hierarchical projects/tasks, and performing knowledge retrieval with document upload capabilities. Always prioritize Archon first when searching external documentation before using other sources.

View skill

n8n-code-javascript

Documentation

This Claude Skill provides expert guidance for writing JavaScript code in n8n's Code nodes. It covers essential n8n-specific syntax like `$input`/`$json` variables, HTTP helpers, and DateTime handling, while troubleshooting common errors. Use it when developing n8n workflows that require custom JavaScript processing in Code nodes.

View skill