跳转到主要内容
可选步骤:仅在您不使用任何负载均衡器或代理服务器时需要。
为了使您的 Kodus 实例可以从外部系统访问(代码审查 webhook 和公共访问所必需),您需要使用 Nginx 配置反向代理。 以下是两个子域的 Nginx 配置示例:
# Kodus Web 应用程序的服务器块
server {
    listen 80;
    server_name kodus-web.yourdomain.com; # 替换为您实际的 Web 应用域名

    location / {
        proxy_pass http://localhost:3000; # 指向 Kodus Web 应用容器
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        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;
        proxy_cache_bypass $http_upgrade;
        proxy_buffer_size 16k;
        proxy_buffers 8 16k;
        proxy_busy_buffers_size 32k;
    }
}

# Kodus API 的服务器块
server {
    listen 80;
    server_name kodus-api.yourdomain.com; # 替换为您实际的 API 域名

    location ~ ^/(github|gitlab|bitbucket|azure-repos)/webhook {
        proxy_pass http://localhost:3332; # 指向 Kodus Webhooks 服务
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        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;
        proxy_cache_bypass $http_upgrade;
    }

    location / {
        proxy_pass http://localhost:3001; # 指向 Kodus API 服务
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        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;
        proxy_cache_bypass $http_upgrade;
    }
}
将此配置保存到 /etc/nginx/sites-available/kodus(或您选择的名称,例如,如果愿意,可以将 kodus-webkodus-api 作为单独的文件),并创建符号链接以启用它:
sudo ln -s /etc/nginx/sites-available/kodus /etc/nginx/sites-enabled/
sudo nginx -t  # 测试配置
sudo systemctl reload nginx  # 应用更改
反向代理的重要配置更新:在使用 kodus-web.yourdomain.comkodus-api.yourdomain.com(或您选择的子域)设置反向代理后,您必须确保您的 .env 文件正确反映这些公共 URL。具体来说,请验证:
  • WEB_HOSTNAME_API:应设置为仅公共 API 的主机名(例如,kodus-api.yourdomain.com),不包含任何协议(http://https://)。
  • WEB_PORT_API:应对应于您的 API 可访问的公共端口(HTTPS 通常为 443,HTTP 通常为 80)。前端用于调用 API 的方案(http/https)通常将从此端口推断,或在前端逻辑中硬编码为使用 HTTPS。
  • Webhook URL(例如,API_GITHUB_CODE_MANAGEMENT_WEBHOOK):确保在您的 .env 文件中更新这些,以使用包含方案的完整公共 API 域名(例如,https://kodus-api.yourdomain.com/github/webhook)。
如果未正确更新这些内容,可能会导致身份验证问题、Web 应用程序无法连接到 API 或 webhook 失效。

启用 SSL(推荐)

对于生产部署,我们强烈建议使用 Let’s Encrypt 设置 SSL:
# 安装 Let's Encrypt 的 Certbot
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx

# 为两个域名获取并安装证书
sudo certbot --nginx -d kodus-web.yourdomain.com -d kodus-api.yourdomain.com # 替换为您实际的域名
这将自动配置您的 Nginx 设置以使用 HTTPS,并为两个子域重定向 HTTP 流量。