easy-devops 0.2.7 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +97 -53
  2. package/install.sh +34 -12
  3. package/package.json +11 -12
  4. package/{cli → src/cli}/index.js +28 -6
  5. package/{cli → src/cli}/managers/domain-manager.js +143 -35
  6. package/{cli → src/cli}/managers/nginx-manager.js +43 -10
  7. package/src/cli/managers/ssl-manager.js +678 -0
  8. package/{cli → src/cli}/menus/dashboard.js +1 -1
  9. package/{cli → src/cli}/menus/settings.js +27 -8
  10. package/{cli → src/cli}/menus/update.js +1 -1
  11. package/{core → src/core}/config.js +5 -2
  12. package/{core → src/core}/db.js +1 -1
  13. package/{core → src/core}/detector.js +50 -87
  14. package/{core → src/core}/nginx-conf-generator.js +101 -64
  15. package/src/core/platform.js +61 -0
  16. package/{core → src/core}/shell.js +38 -2
  17. package/src/core/validators.js +96 -0
  18. package/{dashboard → src/dashboard}/lib/cert-reader.js +5 -5
  19. package/{dashboard → src/dashboard}/lib/nginx-service.js +47 -77
  20. package/src/dashboard/public/img/icon.png +0 -0
  21. package/src/dashboard/public/img/icon_b.png +0 -0
  22. package/{dashboard → src/dashboard}/public/js/app.js +206 -30
  23. package/{dashboard → src/dashboard}/routes/domains.js +96 -72
  24. package/{dashboard → src/dashboard}/routes/settings.js +19 -11
  25. package/src/dashboard/routes/ssl.js +281 -0
  26. package/src/dashboard/views/index.ejs +652 -0
  27. package/src/dashboard/views/partials/domain-form.ejs +356 -0
  28. package/src/dashboard/views/partials/domains-panel.ejs +101 -0
  29. package/src/dashboard/views/partials/login.ejs +167 -0
  30. package/src/dashboard/views/partials/nginx-panel.ejs +153 -0
  31. package/src/dashboard/views/partials/overview.ejs +142 -0
  32. package/src/dashboard/views/partials/settings-panel.ejs +68 -0
  33. package/src/dashboard/views/partials/sidebar.ejs +96 -0
  34. package/src/dashboard/views/partials/ssl-panel.ejs +176 -0
  35. package/{lib → src/lib}/installer/nvm-bootstrap.sh +8 -8
  36. package/{lib → src/lib}/installer/picker.sh +33 -16
  37. package/cli/managers/ssl-manager.js +0 -963
  38. package/dashboard/routes/ssl.js +0 -140
  39. package/dashboard/views/index.ejs +0 -327
  40. package/dashboard/views/partials/domain-form.ejs +0 -257
  41. package/dashboard/views/partials/domains-panel.ejs +0 -66
  42. package/dashboard/views/partials/login.ejs +0 -50
  43. package/dashboard/views/partials/nginx-panel.ejs +0 -90
  44. package/dashboard/views/partials/overview.ejs +0 -67
  45. package/dashboard/views/partials/settings-panel.ejs +0 -37
  46. package/dashboard/views/partials/sidebar.ejs +0 -45
  47. package/dashboard/views/partials/ssl-panel.ejs +0 -95
  48. /package/{cli → src/cli}/managers/node-manager.js +0 -0
  49. /package/{cli → src/cli}/menus/.gitkeep +0 -0
  50. /package/{cli → src/cli}/menus/domains.js +0 -0
  51. /package/{cli → src/cli}/menus/nginx.js +0 -0
  52. /package/{cli → src/cli}/menus/nodejs.js +0 -0
  53. /package/{cli → src/cli}/menus/ssl.js +0 -0
  54. /package/{dashboard → src/dashboard}/lib/.gitkeep +0 -0
  55. /package/{dashboard → src/dashboard}/lib/domains-db.js +0 -0
  56. /package/{dashboard → src/dashboard}/lib/nginx-conf-generator.js +0 -0
  57. /package/{dashboard → src/dashboard}/routes/.gitkeep +0 -0
  58. /package/{dashboard → src/dashboard}/routes/auth.js +0 -0
  59. /package/{dashboard → src/dashboard}/routes/nginx.js +0 -0
  60. /package/{dashboard → src/dashboard}/server.js +0 -0
  61. /package/{lib → src/lib}/installer/.gitkeep +0 -0
  62. /package/{lib → src/lib}/installer/detect.sh +0 -0
  63. /package/{lib → src/lib}/installer/node-versions.sh +0 -0
  64. /package/{lib → src/lib}/installer/progress.sh +0 -0
  65. /package/{lib → src/lib}/installer/winget-install.ps1 +0 -0
@@ -15,14 +15,16 @@ export default async function settingsMenu() {
15
15
  while (true) {
16
16
  // T013: display current values
17
17
  const passwordDisplay = config.dashboardPassword ? '***' : '(not set)';
18
+ const emailDisplay = config.acmeEmail || '(not set)';
18
19
 
19
20
  console.log();
20
- console.log(chalk.bold('⚙️ Settings'));
21
+ console.log(chalk.bold('⚙️ Settings'));
21
22
  console.log(chalk.gray('─'.repeat(40)));
22
- console.log(` Dashboard Port: ${chalk.cyan(config.dashboardPort)}`);
23
- console.log(` Dashboard Password: ${chalk.cyan(passwordDisplay)}`);
24
- console.log(` Nginx Directory: ${chalk.cyan(config.nginxDir)}`);
25
- console.log(` Certbot Directory: ${chalk.cyan(config.certbotDir)}`);
23
+ console.log(` Dashboard Port: ${chalk.cyan(config.dashboardPort)}`);
24
+ console.log(` Dashboard Password: ${chalk.cyan(passwordDisplay)}`);
25
+ console.log(` Nginx Directory: ${chalk.cyan(config.nginxDir)}`);
26
+ console.log(` SSL Directory: ${chalk.cyan(config.sslDir)}`);
27
+ console.log(` ACME Email: ${chalk.cyan(emailDisplay)}`);
26
28
  console.log();
27
29
 
28
30
  // T014: field selection
@@ -31,10 +33,11 @@ export default async function settingsMenu() {
31
33
  name: 'field',
32
34
  message: 'Select a field to edit:',
33
35
  choices: [
34
- { name: `Dashboard Port (${config.dashboardPort})`, value: 'dashboardPort' },
36
+ { name: `Dashboard Port (${config.dashboardPort})`, value: 'dashboardPort' },
35
37
  { name: `Dashboard Password (${passwordDisplay})`, value: 'dashboardPassword' },
36
- { name: `Nginx Directory (${config.nginxDir})`, value: 'nginxDir' },
37
- { name: `Certbot Directory (${config.certbotDir})`, value: 'certbotDir' },
38
+ { name: `Nginx Directory (${config.nginxDir})`, value: 'nginxDir' },
39
+ { name: `SSL Directory (${config.sslDir})`, value: 'sslDir' },
40
+ { name: `ACME Email (${emailDisplay})`, value: 'acmeEmail' },
38
41
  { name: '← Back', value: 'back' },
39
42
  ],
40
43
  }]);
@@ -69,6 +72,22 @@ export default async function settingsMenu() {
69
72
  config.dashboardPassword = value;
70
73
  saveConfig(config); // T016
71
74
 
75
+ } else if (field === 'acmeEmail') {
76
+ const { value } = await inquirer.prompt([{
77
+ type: 'input',
78
+ name: 'value',
79
+ message: 'ACME Email (Let\'s Encrypt):',
80
+ default: config.acmeEmail || '',
81
+ validate(input) {
82
+ if (input && !input.includes('@')) {
83
+ return chalk.red('Please enter a valid email address.');
84
+ }
85
+ return true;
86
+ },
87
+ }]);
88
+ config.acmeEmail = value;
89
+ saveConfig(config); // T016
90
+
72
91
  } else {
73
92
  const { value } = await inquirer.prompt([{
74
93
  type: 'input',
@@ -27,7 +27,7 @@ import { getDashboardStatus, startDashboard, stopDashboard } from './dashboard.j
27
27
 
28
28
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
29
29
  const require = createRequire(import.meta.url);
30
- const { version: currentVersion } = require('../../package.json');
30
+ const { version: currentVersion } = require('../../../package.json');
31
31
 
32
32
  // ─── Version helpers ──────────────────────────────────────────────────────────
33
33
 
@@ -6,16 +6,18 @@ const platform = os.platform();
6
6
  const DEFAULTS = {
7
7
  linux: {
8
8
  nginxDir: '/etc/nginx',
9
- certbotDir: '/etc/letsencrypt',
9
+ sslDir: '/etc/easy-devops/ssl',
10
10
  dashboardPort: 6443,
11
11
  dashboardPassword: '',
12
+ acmeEmail: '',
12
13
  os: 'linux',
13
14
  },
14
15
  win32: {
15
16
  nginxDir: 'C:\\nginx',
16
- certbotDir: 'C:\\certbot',
17
+ sslDir: 'C:\\easy-devops\\ssl',
17
18
  dashboardPort: 6443,
18
19
  dashboardPassword: '',
20
+ acmeEmail: '',
19
21
  os: 'win32',
20
22
  },
21
23
  };
@@ -25,6 +27,7 @@ const defaultConfig = DEFAULTS[platform] ?? DEFAULTS.linux;
25
27
  export function loadConfig() {
26
28
  const stored = dbGet('config');
27
29
  if (stored) {
30
+ // Merge with defaults to ensure new fields have default values
28
31
  return { ...defaultConfig, ...stored };
29
32
  }
30
33
  const config = { ...defaultConfig };
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
 
6
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
- const DATA_DIR = path.join(__dirname, '..', 'data');
7
+ const DATA_DIR = path.join(__dirname, '..', '..', 'data');
8
8
  const DB_PATH = path.join(DATA_DIR, 'easy-devops.sqlite');
9
9
 
10
10
  try {
@@ -1,28 +1,28 @@
1
1
  /**
2
- * core/detector.js
3
- *
4
- * Automatic server environment detection.
5
- *
6
- * DB key: 'system-detection'
7
- *
8
- * Exported functions:
9
- * - runDetection() — collects all system info, writes to DB, silent on success
10
- * - showSystemStatus() — reads DB, prints chalk-formatted table to stdout
11
- * - getDetectionResult() — thin wrapper around dbGet('system-detection') for other modules
12
- *
13
- * SystemDetectionResult schema:
14
- * {
15
- * detectedAt: string, // ISO 8601 timestamp
16
- * os: { type, release },
17
- * nodejs: { version },
18
- * npm: { installed, version },
19
- * nginx: { installed, version, path },
20
- * certbot: { installed, version }
21
- * }
22
- *
23
- * Returns undefined (never throws) when detection has never run.
24
- * Other modules should import getDetectionResult() rather than coupling to the raw DB key.
25
- */
2
+ * core/detector.js
3
+ *
4
+ * Automatic server environment detection.
5
+ *
6
+ * DB key: 'system-detection'
7
+ *
8
+ * Exported functions:
9
+ * - runDetection() — collects all system info, writes to DB, silent in success
10
+ * - showSystemStatus() — reads DB, prints chalk-formatted table to stdout
11
+ * - getDetectionResult() — thin wrapper around dbGet('system-detection') for other modules
12
+ *
13
+ * SystemDetectionResult schema:
14
+ * {
15
+ * detectedAt: string, // ISO 8601 timestamp
16
+ * os: { type, release },
17
+ * nodejs: { version },
18
+ * npm: { installed, version },
19
+ * nginx: { installed, version, path },
20
+ * acme: { type: 'acme-client' } // Pure Node.js ACME client
21
+ * }
22
+ *
23
+ * Returns undefined (never throws) when detection has never run.
24
+ * Other modules should import getDetectionResult() rather than coupling to the raw DB key.
25
+ */
26
26
 
27
27
  import os from 'os';
28
28
  import chalk from 'chalk';
@@ -46,7 +46,7 @@ export async function runDetection() {
46
46
  // npm
47
47
  const npmResult = await run('npm --version');
48
48
  const npmInfo = npmResult.success
49
- ? { installed: true, version: npmResult.stdout }
49
+ ? { installed: true, version: npmResult.stdout.trim() }
50
50
  : { installed: false, version: null };
51
51
 
52
52
  // nginx detection — two-step on Windows: PATH first, configured path as fallback.
@@ -101,36 +101,9 @@ export async function runDetection() {
101
101
  }
102
102
  }
103
103
 
104
- // certbot — try PATH first, then the well-known Windows install location.
105
- // The winget/official installer puts certbot in C:\Program Files\Certbot\bin\
106
- // which may not be reflected in the current session PATH immediately after install.
107
- const CERTBOT_WIN_EXE = 'C:\\Program Files\\Certbot\\bin\\certbot.exe';
108
- let certbotExe = 'certbot';
109
-
110
- if (platform === 'win32') {
111
- const pathCheck = await run('where.exe certbot');
112
- if (pathCheck.exitCode !== 0 || !pathCheck.stdout.trim()) {
113
- // Fall back to the known install path
114
- const exeCheck = await run(`Test-Path "${CERTBOT_WIN_EXE}"`);
115
- if (exeCheck.stdout.trim().toLowerCase() === 'true') {
116
- certbotExe = CERTBOT_WIN_EXE;
117
- }
118
- }
119
- }
120
-
121
- // Use & "..." in PowerShell when the exe is a full path, otherwise bare name
122
- const certbotCmd = (platform === 'win32' && certbotExe !== 'certbot')
123
- ? `& "${certbotExe}" --version`
124
- : `${certbotExe} --version`;
125
- const certbotResult = await run(certbotCmd);
126
- const certbotCombined = certbotResult.stdout + ' ' + certbotResult.stderr;
127
- let certbotInfo;
128
- if (certbotResult.success || certbotCombined.match(/certbot\s+[\d.]+/i)) {
129
- const match = certbotCombined.match(/certbot\s+([\d.]+)/i);
130
- certbotInfo = { installed: true, version: match ? match[1] : null };
131
- } else {
132
- certbotInfo = { installed: false, version: null };
133
- }
104
+ // ACME client — pure Node.js (acme-client npm package)
105
+ // No external binary needed; detection is informational only.
106
+ const acmeInfo = { type: 'acme-client' };
134
107
 
135
108
  const result = {
136
109
  detectedAt: new Date().toISOString(),
@@ -138,7 +111,7 @@ export async function runDetection() {
138
111
  nodejs: nodejsInfo,
139
112
  npm: npmInfo,
140
113
  nginx: nginxInfo,
141
- certbot: certbotInfo,
114
+ acme: acmeInfo,
142
115
  };
143
116
 
144
117
  try {
@@ -177,26 +150,21 @@ export function showSystemStatus() {
177
150
  if (result.npm.installed) {
178
151
  console.log(label('npm') + chalk.white(result.npm.version));
179
152
  } else {
180
- console.log(label('npm') + chalk.red('✗ not installed'));
153
+ console.log(label('npm') + chalk.red('✗ not installed'));
181
154
  }
182
155
 
183
156
  // nginx
184
157
  if (result.nginx.installed) {
185
158
  const parts = [chalk.green('✓'), result.nginx.version, result.nginx.path]
186
159
  .filter(Boolean)
187
- .join(' ');
160
+ .join(' ');
188
161
  console.log(label('nginx') + parts);
189
162
  } else {
190
- console.log(label('nginx') + chalk.red('✗ not installed'));
163
+ console.log(label('nginx') + chalk.red('✗ not installed'));
191
164
  }
192
165
 
193
- // certbot
194
- if (result.certbot.installed) {
195
- const parts = [chalk.green('✓'), result.certbot.version].filter(Boolean).join(' ');
196
- console.log(label('certbot') + parts);
197
- } else {
198
- console.log(label('certbot') + chalk.red('✗ not installed'));
199
- }
166
+ // ACME
167
+ console.log(label('ACME') + chalk.green('acme-client (Node.js)'));
200
168
 
201
169
  console.log(SEP);
202
170
  console.log(chalk.gray(`Last detected: ${result.detectedAt}`));
@@ -206,14 +174,14 @@ export function showSystemStatus() {
206
174
  // ─── getDetectionResult ───────────────────────────────────────────────────────
207
175
 
208
176
  /**
209
- * Returns the latest SystemDetectionResult from the database,
210
- * or undefined if detection has never run.
211
- *
212
- * Usage by other modules:
213
- * import { getDetectionResult } from '../core/detector.js';
214
- * const detection = getDetectionResult();
215
- * const { nginx } = detection ?? {};
216
- */
177
+ * Returns the latest SystemDetectionResult from the database,
178
+ * or undefined if detection has never run.
179
+ *
180
+ * Usage by other modules:
181
+ * import { getDetectionResult } from '../core/detector.js';
182
+ * const detection = getDetectionResult();
183
+ * const { nginx } = detection ?? {};
184
+ */
217
185
  export function getDetectionResult() {
218
186
  return dbGet('system-detection');
219
187
  }
@@ -221,15 +189,15 @@ export function getDetectionResult() {
221
189
  // ─── formatStatusLine ─────────────────────────────────────────────────────────
222
190
 
223
191
  /**
224
- * Returns a compact inline status string for embedding in the main menu header.
225
- * Format: "nginx: ✅ v1.26 | certbot: ✅ | node: v20.11"
226
- * Returns a warning string if detection result is undefined.
227
- */
192
+ * Returns a compact inline status string for embedding in the main menu header.
193
+ * Format: "nginx: ✅ v1.26 | ACME: acme-client | node: v20.11"
194
+ * Returns a warning string if detection result is undefined.
195
+ */
228
196
  export function formatStatusLine() {
229
197
  const result = getDetectionResult();
230
198
 
231
199
  if (!result) {
232
- return chalk.yellow('⚠ System detection not available — run detection first.');
200
+ return chalk.yellow('⚠ System detection not available — run detection first.');
233
201
  }
234
202
 
235
203
  const parts = [];
@@ -242,16 +210,11 @@ export function formatStatusLine() {
242
210
  parts.push(`nginx: ${chalk.yellow('⚠ not found')}`);
243
211
  }
244
212
 
245
- // certbot
246
- if (result.certbot.installed) {
247
- const ver = result.certbot.version ? ` v${result.certbot.version}` : '';
248
- parts.push(`certbot: ✅${ver}`);
249
- } else {
250
- parts.push(`certbot: ${chalk.yellow('⚠ not found')}`);
251
- }
213
+ // ACME (always available since it's pure Node.js)
214
+ parts.push('ACME: ✅ acme-client');
252
215
 
253
216
  // node
254
217
  parts.push(`node: ${result.nodejs.version}`);
255
218
 
256
- return parts.join(' | ');
219
+ return parts.join(' | ');
257
220
  }
@@ -10,14 +10,13 @@
10
10
  import fs from 'fs/promises';
11
11
  import path from 'path';
12
12
  import { loadConfig } from './config.js';
13
-
14
- const isWindows = process.platform === 'win32';
13
+ import { isWindows } from './platform.js';
15
14
 
16
15
  /** Returns the conf.d directory for domain config files. */
17
- function getConfDDir(nginxDir) {
16
+ export function getConfDDir(nginxDir) {
18
17
  return isWindows
19
18
  ? path.join(nginxDir, 'conf', 'conf.d')
20
- : path.join(nginxDir, 'conf.d', 'conf.d');
19
+ : path.join(nginxDir, 'conf.d');
21
20
  }
22
21
 
23
22
  /** Returns the path to nginx.conf. */
@@ -31,9 +30,9 @@ function getNginxConfPath(nginxDir) {
31
30
  function buildIncludeLine(nginxDir) {
32
31
  if (isWindows) {
33
32
  const fwd = nginxDir.replace(/\\/g, '/');
34
- return ` include "${fwd}/conf/conf.d/*.conf";`;
33
+ return ` include "${fwd}/conf/conf.d/*.conf";`;
35
34
  }
36
- return ` include ${nginxDir}/conf.d/*.conf;`;
35
+ return ` include ${nginxDir}/conf.d/*.conf;`;
37
36
  }
38
37
 
39
38
  /**
@@ -74,6 +73,8 @@ export const DOMAIN_DEFAULTS = {
74
73
  backendHost: '127.0.0.1',
75
74
  upstreamType: 'http', // 'http' | 'https' | 'ws'
76
75
  www: false,
76
+ wildcard: false, // *.example.com server_name; forces DNS-01
77
+ enabled: true, // false = conf file renamed to .conf.disabled
77
78
  ssl: {
78
79
  enabled: false,
79
80
  certPath: '',
@@ -115,6 +116,8 @@ export function migrateDomain(d) {
115
116
  return {
116
117
  ...DOMAIN_DEFAULTS,
117
118
  ...d,
119
+ wildcard: d.wildcard ?? false,
120
+ enabled: d.enabled ?? true,
118
121
  ssl: { ...DOMAIN_DEFAULTS.ssl, ...d.ssl },
119
122
  performance: { ...DOMAIN_DEFAULTS.performance, ...d.performance },
120
123
  security: { ...DOMAIN_DEFAULTS.security, ...d.security },
@@ -142,6 +145,8 @@ export function migrateDomain(d) {
142
145
  },
143
146
  security: { ...DOMAIN_DEFAULTS.security },
144
147
  advanced: { ...DOMAIN_DEFAULTS.advanced },
148
+ wildcard: d.wildcard ?? false,
149
+ enabled: d.enabled ?? true,
145
150
  configFile: d.configFile ?? null,
146
151
  createdAt: d.createdAt ?? new Date().toISOString(),
147
152
  updatedAt: d.updatedAt ?? new Date().toISOString(),
@@ -154,10 +159,10 @@ export function migrateDomain(d) {
154
159
  * Builds an nginx server block configuration from a domain object.
155
160
  * @param {Object} domain - Domain configuration object (v2 schema)
156
161
  * @param {string} nginxDir - Nginx directory path
157
- * @param {string} certbotDir - Certbot directory path
162
+ * @param {string} sslDir - SSL certificate directory path
158
163
  * @returns {string} Complete nginx conf content for the domain
159
164
  */
160
- export function buildConf(domain, nginxDir, certbotDir) {
165
+ export function buildConf(domain, nginxDir, sslDir) {
161
166
  const {
162
167
  name,
163
168
  port,
@@ -173,27 +178,38 @@ export function buildConf(domain, nginxDir, certbotDir) {
173
178
  // Determine proxy scheme based on upstreamType
174
179
  const proxyScheme = upstreamType === 'https' ? 'https' : 'http';
175
180
 
181
+ // Detect if backendHost is a full external URL (e.g. https://app.vercel.app)
182
+ const backendIsUrl = /^https?:\/\//i.test(backendHost);
183
+
184
+ // Host header: for external URLs send the upstream's own hostname so the
185
+ // remote service (Vercel, Railway, etc.) can route the request correctly.
186
+ // For local upstreams keep $host (the client's domain).
187
+ let upstreamHostHeader = '$host';
188
+ if (backendIsUrl) {
189
+ try { upstreamHostHeader = new URL(backendHost).host; } catch { /* keep $host */ }
190
+ }
191
+
176
192
  // Build proxy headers (always include standard set)
177
193
  let proxyHeaders = `
178
- proxy_set_header Host $host;
179
- proxy_set_header X-Real-IP $remote_addr;
180
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
181
- proxy_set_header X-Forwarded-Proto $scheme;`;
194
+ proxy_set_header Host ${upstreamHostHeader};
195
+ proxy_set_header X-Real-IP $remote_addr;
196
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
197
+ proxy_set_header X-Forwarded-Proto $scheme;`;
182
198
 
183
199
  // Add WebSocket headers if upstreamType is 'ws'
184
200
  if (upstreamType === 'ws') {
185
201
  proxyHeaders = `
186
- proxy_http_version 1.1;
187
- proxy_set_header Upgrade $http_upgrade;
188
- proxy_set_header Connection "upgrade";${proxyHeaders}`;
202
+ proxy_http_version 1.1;
203
+ proxy_set_header Upgrade $http_upgrade;
204
+ proxy_set_header Connection "upgrade";${proxyHeaders}`;
189
205
  }
190
206
 
191
207
  // Build rate limiting zone name (dots → underscores)
192
208
  const rateLimitZone = name.replace(/\./g, '_').replace(/\*/g, 'wildcard');
193
209
 
194
- // SSL cert/key paths - use certbot convention if empty
195
- const certPath = ssl?.certPath || `${certbotDir}/live/${name}/fullchain.pem`;
196
- const keyPath = ssl?.keyPath || `${certbotDir}/live/${name}/privkey.pem`;
210
+ // SSL cert/key paths - use sslDir convention if empty
211
+ const certPath = ssl?.certPath || `${sslDir}/${name}/fullchain.pem`;
212
+ const keyPath = ssl?.keyPath || `${sslDir}/${name}/privkey.pem`;
197
213
 
198
214
  // Build the config sections
199
215
  const sections = [];
@@ -201,61 +217,65 @@ export function buildConf(domain, nginxDir, certbotDir) {
201
217
  // ─── Rate Limit Zone Comment ────────────────────────────────────────────────
202
218
  if (security?.rateLimit) {
203
219
  sections.push(`# Rate limit zone — add to nginx.conf http block:
204
- # limit_req_zone $binary_remote_addr zone=${rateLimitZone}:10m rate=${security.rateLimitRate}r/s;`);
220
+ # limit_req_zone $binary_remote_addr zone=${rateLimitZone}:10m rate=${security.rateLimitRate}r/s;`);
205
221
  }
206
222
 
207
- // ─── WWW Redirect (non-SSL only) ────────────────────────────────────────────
208
- if (www && !ssl?.enabled) {
223
+ // Compute server_name: wildcard covers all subdomains; www adds explicit www
224
+ const wildcardEnabled = domain.wildcard ?? false;
225
+ const mainServerNames = wildcardEnabled ? `*.${name} ${name}` : (www ? `${name} www.${name}` : name);
226
+ const redirectServerNames = wildcardEnabled ? `*.${name} ${name}` : (www ? `${name} www.${name}` : name);
227
+
228
+ // ─── WWW Redirect (non-SSL, non-wildcard only) ───────────────────────────────
229
+ if (www && !ssl?.enabled && !wildcardEnabled) {
209
230
  sections.push(`server {
210
- listen 80;
211
- server_name www.${name};
212
- return 301 http://${name}$request_uri;
213
- }`);
231
+ listen 80;
232
+ server_name www.${name};
233
+ return 301 http://${name}$request_uri;
234
+ }`);
214
235
  }
215
236
 
216
237
  // ─── HTTP → HTTPS Redirect ──────────────────────────────────────────────────
217
238
  if (ssl?.enabled && ssl?.redirect) {
218
- const serverNames = www ? `${name} www.${name}` : name;
219
239
  sections.push(`server {
220
- listen 80;
221
- server_name ${serverNames};
222
- return 301 https://${name}$request_uri;
223
- }`);
240
+ listen 80;
241
+ server_name ${redirectServerNames};
242
+ return 301 https://${name}$request_uri;
243
+ }`);
224
244
  }
225
245
 
226
246
  // ─── Main Server Block ──────────────────────────────────────────────────────
227
247
  const listenPort = ssl?.enabled ? '443 ssl' : '80';
228
- const serverNames = www ? `${name} www.${name}` : name;
248
+ const serverNames = mainServerNames;
229
249
 
230
250
  const mainBlock = [];
231
251
 
232
252
  mainBlock.push(`server {`);
233
- mainBlock.push(` listen ${listenPort};`);
234
- mainBlock.push(` server_name ${serverNames};`);
253
+ mainBlock.push(` listen ${listenPort};`);
254
+ mainBlock.push(` server_name ${serverNames};`);
235
255
 
236
256
  // SSL configuration
237
257
  if (ssl?.enabled) {
238
258
  mainBlock.push(``);
239
- mainBlock.push(` ssl_certificate ${certPath};`);
240
- mainBlock.push(` ssl_certificate_key ${keyPath};`);
259
+ mainBlock.push(` ssl_certificate ${certPath};`);
260
+ mainBlock.push(` ssl_certificate_key ${keyPath};`);
241
261
  }
242
262
 
243
263
  // Performance: client_max_body_size
244
264
  mainBlock.push(``);
245
- mainBlock.push(` client_max_body_size ${performance?.maxBodySize || '10m'};`);
265
+ mainBlock.push(` client_max_body_size ${performance?.maxBodySize || '10m'};`);
246
266
 
247
267
  // Performance: gzip
248
268
  if (performance?.gzip) {
249
- mainBlock.push(` gzip on;`);
250
- mainBlock.push(` gzip_types ${performance?.gzipTypes || DOMAIN_DEFAULTS.performance.gzipTypes};`);
269
+ mainBlock.push(` gzip on;`);
270
+ mainBlock.push(` gzip_types ${performance?.gzipTypes || DOMAIN_DEFAULTS.performance.gzipTypes};`);
251
271
  }
252
272
 
253
273
  // Performance: proxy buffering
254
274
  if (performance?.proxyBuffers) {
255
- mainBlock.push(` proxy_buffering on;`);
275
+ mainBlock.push(` proxy_buffering on;`);
256
276
  }
257
277
 
258
- // Logging
278
+ // Logging - use platform-appropriate log path
259
279
  if (advanced?.accessLog) {
260
280
  const logDir = isWindows ? `${nginxDir.replace(/\\/g, '/')}/logs` : '/var/log/nginx';
261
281
  mainBlock.push(` access_log ${logDir}/${name}.access.log;`);
@@ -263,56 +283,73 @@ export function buildConf(domain, nginxDir, certbotDir) {
263
283
 
264
284
  // ─── Location Block ─────────────────────────────────────────────────────────
265
285
  mainBlock.push(``);
266
- mainBlock.push(` location / {`);
267
- mainBlock.push(` proxy_pass ${proxyScheme}://${backendHost}:${port};`);
286
+ mainBlock.push(` location / {`);
287
+ // proxy_pass: full external URL → use directly (no scheme/port added)
288
+ // local backend → build from scheme + host + port
289
+ const proxyTarget = backendIsUrl
290
+ ? backendHost.replace(/\/$/, '')
291
+ : `${proxyScheme}://${backendHost}:${port}`;
292
+ mainBlock.push(` proxy_pass ${proxyTarget};`);
293
+ // Add proxy_ssl_server_name for external HTTPS upstreams (SNI — required for Vercel, Railway, etc.)
294
+ // Only when: HTTPS URL, not an IP address, not localhost, and nginx itself is not terminating SSL
295
+ // (if nginx has its own cert the backend connection is separate — SNI directive is irrelevant)
296
+ if (backendIsUrl && /^https:/i.test(backendHost) && !ssl?.enabled) {
297
+ let upstreamHostname = '';
298
+ try { upstreamHostname = new URL(backendHost).hostname; } catch { /* skip */ }
299
+ const isIp = /^\d{1,3}(\.\d{1,3}){3}$/.test(upstreamHostname) || upstreamHostname.startsWith('[');
300
+ const isLocal = upstreamHostname === 'localhost' || upstreamHostname === '127.0.0.1';
301
+ if (!isIp && !isLocal) {
302
+ mainBlock.push(` proxy_ssl_server_name on;`);
303
+ }
304
+ }
268
305
  mainBlock.push(proxyHeaders);
269
306
  mainBlock.push(``);
270
- mainBlock.push(` proxy_read_timeout ${performance?.readTimeout || 60}s;`);
271
- mainBlock.push(` proxy_connect_timeout ${performance?.connectTimeout || 10}s;`);
307
+ mainBlock.push(` proxy_read_timeout ${performance?.readTimeout || 60}s;`);
308
+ mainBlock.push(` proxy_connect_timeout ${performance?.connectTimeout || 10}s;`);
272
309
 
273
310
  // Rate limiting
274
311
  if (security?.rateLimit) {
275
312
  mainBlock.push(``);
276
- mainBlock.push(` limit_req zone=${rateLimitZone} burst=${security.rateLimitBurst} nodelay;`);
313
+ mainBlock.push(` limit_req zone=${rateLimitZone} burst=${security.rateLimitBurst} nodelay;`);
277
314
  }
278
315
 
279
316
  // Security headers
280
317
  if (security?.securityHeaders) {
281
318
  mainBlock.push(``);
282
- mainBlock.push(` add_header X-Frame-Options "SAMEORIGIN" always;`);
283
- mainBlock.push(` add_header X-Content-Type-Options "nosniff" always;`);
284
- mainBlock.push(` add_header Referrer-Policy "strict-origin-when-cross-origin" always;`);
319
+ mainBlock.push(` add_header X-Frame-Options "SAMEORIGIN" always;`);
320
+ mainBlock.push(` add_header X-Content-Type-Options "nosniff" always;`);
321
+ mainBlock.push(` add_header Referrer-Policy "strict-origin-when-cross-origin" always;`);
285
322
  }
286
323
 
287
324
  // HSTS
288
325
  if (ssl?.enabled && ssl?.hsts) {
289
326
  mainBlock.push(``);
290
- mainBlock.push(` add_header Strict-Transport-Security "max-age=${ssl.hstsMaxAge}; includeSubDomains" always;`);
327
+ mainBlock.push(` add_header Strict-Transport-Security "max-age=${ssl.hstsMaxAge}; includeSubDomains" always;`);
291
328
  }
292
329
 
293
- mainBlock.push(` }`);
330
+ mainBlock.push(` }`);
294
331
 
295
332
  // Custom error pages
296
333
  if (security?.custom404 || security?.custom50x) {
297
334
  mainBlock.push(``);
298
335
  if (security.custom404) {
299
- mainBlock.push(` error_page 404 /404.html;`);
336
+ mainBlock.push(` error_page 404 /404.html;`);
300
337
  }
301
338
  if (security.custom50x) {
302
- mainBlock.push(` error_page 500 502 503 504 /50x.html;`);
339
+ mainBlock.push(` error_page 500 502 503 504 /50x.html;`);
303
340
  }
304
341
  if (security.custom404) {
305
- mainBlock.push(` location = /404.html { root ${isWindows ? nginxDir.replace(/\\/g, '/') + '/html' : '/usr/share/nginx/html'}; internal; }`);
342
+ mainBlock.push(` location = /404.html { root ${isWindows ? nginxDir.replace(/\\/g, '/') + '/html' : '/usr/share/nginx/html'}; internal; }`);
306
343
  }
307
344
  if (security.custom50x) {
308
- mainBlock.push(` location = /50x.html { root ${isWindows ? nginxDir.replace(/\\/g, '/') + '/html' : '/usr/share/nginx/html'}; internal; }`);
345
+ mainBlock.push(` location = /50x.html { root ${isWindows ? nginxDir.replace(/\\/g, '/') + '/html' : '/usr/share/nginx/html'}; internal; }`);
309
346
  }
310
347
  }
311
348
 
312
349
  // Custom location blocks
313
350
  if (advanced?.customLocations && advanced.customLocations.trim()) {
314
351
  mainBlock.push(``);
315
- mainBlock.push(` # Custom locations`);
352
+ mainBlock.push(` # Custom locations`);
316
353
  mainBlock.push(advanced.customLocations);
317
354
  }
318
355
 
@@ -331,10 +368,10 @@ export function buildConf(domain, nginxDir, certbotDir) {
331
368
  * @returns {Promise<string>} Path to the generated conf file
332
369
  */
333
370
  export async function generateConf(domain) {
334
- const { nginxDir, certbotDir } = loadConfig();
371
+ const { nginxDir, sslDir } = loadConfig();
335
372
  const confDir = getConfDDir(nginxDir);
336
373
  const confPath = path.join(confDir, `${domain.name}.conf`);
337
- const confContent = buildConf(domain, nginxDir, certbotDir);
374
+ const confContent = buildConf(domain, nginxDir, sslDir);
338
375
 
339
376
  // Ensure conf.d directory exists
340
377
  await fs.mkdir(confDir, { recursive: true });
@@ -351,21 +388,21 @@ export async function generateConf(domain) {
351
388
  }
352
389
 
353
390
  /**
354
- * Generates a default certbot path for a domain based on platform.
391
+ * Generates a default SSL certificate path for a domain based on platform.
355
392
  * @param {string} domainName - Domain name
356
393
  * @param {string} platform - 'win32' or 'linux'
357
- * @param {string} certbotDir - Certbot directory from config
394
+ * @param {string} sslDir - SSL directory from config
358
395
  * @returns {Object} { certPath, keyPath }
359
396
  */
360
- export function getDefaultCertPaths(domainName, platform, certbotDir) {
397
+ export function getDefaultCertPaths(domainName, platform, sslDir) {
361
398
  if (platform === 'win32') {
362
399
  return {
363
- certPath: `C:\\Certbot\\live\\${domainName}\\fullchain.pem`,
364
- keyPath: `C:\\Certbot\\live\\${domainName}\\privkey.pem`,
400
+ certPath: `C:\\easy-devops\\ssl\\${domainName}\\fullchain.pem`,
401
+ keyPath: `C:\\easy-devops\\ssl\\${domainName}\\privkey.pem`,
365
402
  };
366
403
  }
367
404
  return {
368
- certPath: `${certbotDir}/live/${domainName}/fullchain.pem`,
369
- keyPath: `${certbotDir}/live/${domainName}/privkey.pem`,
405
+ certPath: `${sslDir}/${domainName}/fullchain.pem`,
406
+ keyPath: `${sslDir}/${domainName}/privkey.pem`,
370
407
  };
371
408
  }