How to manage vHost settings in CloudPanel
Edit the Nginx vHost configuration for a site in CloudPanel. Add custom rules, headers, redirect logic,
On this page
The vHost (virtual host) is the Nginx configuration file for a specific site. CloudPanel generates a default vHost when you create a site. The vHost editor lets you customise it-adding redirect rules, security headers, custom location blocks, and more.
What is a vHost?
On Nginx, each website is configured through a "server block" (equivalent to Apache's Virtual Host). CloudPanel stores these in /etc/nginx/sites-enabled/. The vHost editor in CloudPanel lets you modify the configuration for a site through the browser-changes are written to the Nginx config and applied on save.
Because CloudPanel uses Nginx (not Apache), .htaccess files are not read. Any rules you would normally put in .htaccess-redirects, cache headers, security rules-must instead be added to the vHost configuration.
Edit the vHost
- Log in to CloudPanel and go to Sites → your site
- Click the Vhost tab
- The current Nginx configuration for the site is shown in a code editor
- Make your changes
- Click Save-CloudPanel validates and reloads Nginx automatically
If the vHost config contains an Nginx syntax error, Nginx will fail to reload and the site goes offline. Copy the current vHost to a text file before making changes. If the site goes down after saving, SSH in and check: nginx -t to see the error, then restore the original config.
Adding custom Nginx rules
CloudPanel's vHost has a specific structure. Add custom rules inside the appropriate server { } block, after the default location rules and before the closing brace. Do not delete the existing WordPress or PHP-FPM configuration blocks.
The recommended pattern is to look for a comment like # Custom Rules in the template and insert your additions there.
Common customisations
Redirect /old-page to /new-page:
location = /old-page {
return 301 /new-page;
}
Add security headers:
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
Block access to a specific path:
location ~* /wp-admin/admin-ajax.php {
allow all;
}
location ~* /wp-admin/ {
allow 1.2.3.4; # your IP
deny all;
}
Set browser cache headers for static files:
location ~* \.(jpg|jpeg|png|gif|ico|webp|css|js|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
Test and reload Nginx
CloudPanel reloads Nginx when you save the vHost. To manually test the configuration via SSH:
nginx -t
If the test shows syntax is ok, reload with:
systemctl reload nginx
Reset to default
If you break the vHost configuration and cannot access the site to fix it, restore the default via SSH. The default vHost templates are in CloudPanel's template directory. Alternatively, delete the site and recreate it in CloudPanel (this does not delete website files, only the Nginx configuration).
Related: How to create a website in CloudPanel | How to change PHP version in CloudPanel | How to set up a reverse proxy in CloudPanel | How to connect to your VPS via SSH
Need CloudPanel on a server?
Use CloudPanel on an UnderHost VPS or dedicated server for fast PHP app and WordPress hosting without a heavy panel stack.





















