CI / go-test (push) Canceled after 0s
CI / postgres-durable-first (push) Canceled after 0s
CI / codegen (push) Canceled after 0s
CI / govulncheck (push) Canceled after 0s
CI / race (push) Canceled after 0s
CI / fuzz-smoke (push) Canceled after 0s
CI / golangci (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CodeQL Advanced / Analyze (go) (push) Canceled after 0s
CodeQL Advanced / Analyze (actions) (push) Canceled after 0s
CodeQL Advanced / Analyze (javascript-typescript) (push) Canceled after 0s
Docs CI / build (push) Canceled after 0s
Docs Deploy (GitHub Pages) / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-latest) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-latest) (push) Canceled after 0s
Docs Deploy (GitHub Pages) / deploy (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
// Pure builders for reverse-proxy configs (Nginx / Caddy) and cert commands.
|
|
|
|
export type ProxyServer = 'nginx' | 'caddy';
|
|
export type CertTool = 'certbot' | 'acme.sh';
|
|
|
|
export interface ReverseProxyOptions {
|
|
server: ProxyServer;
|
|
domain: string;
|
|
panelPort: string;
|
|
/** Web base path the panel is served under, e.g. `/panel`. */
|
|
panelPath: string;
|
|
certTool: CertTool;
|
|
}
|
|
|
|
function normalizePath(path: string): string {
|
|
const p = path.trim();
|
|
if (!p) return '/';
|
|
return p.startsWith('/') ? p : `/${p}`;
|
|
}
|
|
|
|
export function buildProxyConfig(o: ReverseProxyOptions): string {
|
|
return o.server === 'nginx' ? buildNginx(o) : buildCaddy(o);
|
|
}
|
|
|
|
function buildNginx(o: ReverseProxyOptions): string {
|
|
const path = normalizePath(o.panelPath);
|
|
const loc = path === '/' ? '/' : `${path.replace(/\/$/, '')}/`;
|
|
return `server {
|
|
listen 443 ssl http2;
|
|
server_name ${o.domain};
|
|
|
|
ssl_certificate /etc/letsencrypt/live/${o.domain}/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/${o.domain}/privkey.pem;
|
|
|
|
location ${loc} {
|
|
proxy_pass http://127.0.0.1:${o.panelPort};
|
|
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_read_timeout 3600s;
|
|
proxy_send_timeout 3600s;
|
|
}
|
|
}`;
|
|
}
|
|
|
|
function buildCaddy(o: ReverseProxyOptions): string {
|
|
const path = normalizePath(o.panelPath);
|
|
if (path === '/') {
|
|
return `${o.domain} {
|
|
reverse_proxy 127.0.0.1:${o.panelPort}
|
|
}`;
|
|
}
|
|
const matcher = `${path.replace(/\/$/, '')}/*`;
|
|
return `${o.domain} {
|
|
reverse_proxy ${matcher} 127.0.0.1:${o.panelPort}
|
|
}`;
|
|
}
|
|
|
|
export function buildCertCommand(o: ReverseProxyOptions): string {
|
|
if (o.certTool === 'certbot') {
|
|
return `certbot certonly --nginx -d ${o.domain}`;
|
|
}
|
|
return `acme.sh --issue -d ${o.domain} --nginx`;
|
|
}
|