Nginx Vhost Config Generator

Generate Centmin Mod Nginx virtual host configuration files for your domain.

Creating Multiple Nginx Vhosts

To create Nginx vhosts (virtual hosts) for your domains, use the nv command or centmin.sh menu option 2. For production sites, use Let's Encrypt SSL (recommended). Run the command once per domain:

# Recommended: Create vhost with Let's Encrypt production SSL nv -d domain1.com -s lelived nv -d domain2.com -s lelived nv -d domain3.com -s lelived # Testing only: Create vhost with self-signed SSL nv -d testdomain.com -s y

Each command creates the Nginx vhost config at /usr/local/nginx/conf/conf.d/yourdomain.com.conf and the web root at /home/nginx/domains/yourdomain.com/public. Use the generator below to preview the configuration before creating your vhosts.

About This Tool

Centmin Mod Nginx server uses a specific vhost structure different from other Nginx web servers. The centmin.sh menu option 2 auto-generates the domain's Nginx vhost conf file. This tool generates reference copies of those default vhost configurations with your domain name substituted in.

This tool generates reference config files only. SSL certificate files (dhparam.pem, .crt, .key) are NOT generated. Use centmin.sh menu option 2 on your server to create vhosts with all necessary files, or follow the manual SSL setup guide.

Enter a domain name and click Generate

Your nginx vhost configuration will appear here.

Change a Domain Name with HTTPS and Let's Encrypt

If you need to rename a domain on your Centmin Mod server while preserving its SSL certificates and web content, follow these steps. This process copies the existing vhost configuration and SSL files to the new domain name, then reissues the SSL certificate.

Make sure DNS for the new domain is already pointing to your server before reissuing SSL certificates.

  1. Copy the SSL certificate directory from the old domain to the new domain:
    cp -a /usr/local/nginx/conf/ssl/olddomain.com /usr/local/nginx/conf/ssl/newdomain.com
  2. Copy the vhost configuration file:
    cp /usr/local/nginx/conf/conf.d/olddomain.com.ssl.conf /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
  3. Replace the old domain name with the new domain inside the copied config:
    sed -i 's/olddomain.com/newdomain.com/g' /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
  4. Copy or move the web root directory:
    cp -a /home/nginx/domains/olddomain.com/ /home/nginx/domains/newdomain.com/
  5. Clean up the old vhost config (optional):
    rm /usr/local/nginx/conf/conf.d/olddomain.com.ssl.conf
  6. Reissue the SSL certificate for the new domain using acmetool, then test and restart Nginx:
    acmetool.sh reissue-only newdomain.com live nginx -t && ngrestart

For more details, see the forum discussion.

Customize Nginx Vhost Templates

Centmin Mod generates Nginx vhost configuration files from internal templates. If you need to customize the default vhost structure, the template files are located at:

  • inc/nginx_addvhost.inc — used by centmin.sh menu option 2 and menu option 22
  • tools/nv.sh — used by the nv command shortcut

These templates use conditional shell variables that must be preserved when making edits:

  • ${DEDI_IP} — the dedicated IP address for the vhost
  • ${vhostname} — the domain name being created
  • $LISTENOPT — listen directive options

Native Nginx $ variables must be backslash-escaped in the templates (e.g., \$request_uri, \$host) so the shell does not interpret them during vhost creation.

Do not remove or rename the shell variables like ${DEDI_IP}, ${vhostname}, or $LISTENOPT — they are required for the vhost creation process to work correctly.

Customizations made directly to these template files will be overwritten when you run cmupdate. For persistent changes, use hooks or override files if available.

For more details, see the forum discussion.