Domains API

nginx virtual host management, SSL certificate issuance, conflict-free port assignment, and configuration editing.

All endpoints are prefixed with /api/domains. Admin only.


Endpoints

MethodPathDescription
GET/domainsList all domains
GET/domains/:nameGet domain detail
POST/domains/createCreate domain
PUT/domains/:nameUpdate domain
DELETE/domains/:nameDelete domain
GET/domains/:name/nginxGet nginx config
PUT/domains/:name/nginxSave nginx config
POST/domains/:name/sslIssue SSL for domain
GET/domains/parentsList parent domains
GET/domains/ports/availableGet next available port
POST/domains/bulk/deleteBulk delete domains

Request/Response

POST /domains/create

Creates a domain or subdomain. Creates the document root (default /var/www/[domain]), a styled index.html landing page if none exists, writes [domain].conf to /etc/nginx/conf.d/, and issues a Let's Encrypt certificate when SSL is enabled.

{
  "domain": "app.example.com",
  "type": "subdomain",
  "parentDomain": "example.com",
  "port": 0,
  "root": "",
  "ssl": true
}
FieldTypeDescription
domainstringFull domain or subdomain name
typedomain \subdomainDomain type
parentDomainstringRequired for subdomains — the associated parent domain (must exist)
portnumberOptional. If empty/0, a free port is auto-assigned (no conflicts). Verified free when provided.
rootstringOptional document root. Defaults to /var/www/[domain].
sslbooleanAuto-issue a Let's Encrypt certificate (default true).

Response

{
  "success": true,
  "domain": {
    "domain": "app.example.com",
    "type": "subdomain",
    "parentDomain": "example.com",
    "port": 443,
    "root": "/var/www/app.example.com",
    "sslEnabled": true,
    "sslError": ""
  }
}

PUT /domains/:name

{
  "port": 8443,
  "root": "/var/www/app.example.com",
  "sslEnabled": true
}

Changing the port to one already in use by another domain, vhost, or service returns a 400 error without touching any config.

PUT /domains/:name/nginx

{
  "content": "server { listen 80; server_name app.example.com; ... }"
}

Part of NexusPanel API Reference

← Back to Documentation