nginx反代sqtracker配置
2023-5-4 21:28:16 Author: blog.upx8.com(查看原文) 阅读量:34 收藏

注释掉traefik的相关配置:

services:
  traefik:
    image: "traefik:v2.5"
    container_name: "sq_traefik"
    command:
      - "--api.insecure=true"
      - "--providers.file=true"
      - "--providers.file.filename=/config/traefik.yml"
      - "--entrypoints.webinsecure.address=:80"
      - "--entrypoints.web.address=:443"
      - "--entryPoints.web.proxyProtocol.insecure"
      - "--entryPoints.web.forwardedHeaders.insecure"
      - "--certificatesresolvers.tlsresolver.acme.email=example.com"
      - "--certificatesresolvers.tlsresolver.acme.storage=/letsencrypt/acme.json"
      - "--certificatesresolvers.tlsresolver.acme.httpchallenge=true"
      - "--certificatesresolvers.tlsresolver.acme.httpchallenge.entrypoint=webinsecure"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - ./letsencrypt:/letsencrypt
      - ./traefik.yml:/config/traefik.yml

新建nginx配置文件:

nano /etc/nginx/sites-available/sqtracker

写入如下配置:

server {
    listen 80;
    server_name sqtracker.example.com;
    client_max_body_size 0;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /api/ {
        proxy_pass http://127.0.0.1:3001/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /sq/ {
        proxy_pass http://127.0.0.1:3001;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

启用新的nginx配置:

ln -s /etc/nginx/sites-available/sqtracker /etc/nginx/sites-enabled/sqtracker

签发ssl证书:

certbot --nginx

看下api容器的log:

docker compose logs -f api

如果回显有200状态码,并且能够显示出访客的公网ip说明正常:


文章来源: https://blog.upx8.com/3505
如有侵权请联系:admin#unsafe.sh