Adding custom headers is a useful way to identify, trace, or control web traffic across a hosted environment. This guide walks through the process of adding the HTTP header X-Hosted-By: ExampleHost to all websites running on a Plesk server, across both nginx and Apache layers.
Why Add a Custom Header?
Custom HTTP headers can:
- Identify the infrastructure powering your site (e.g., for branding or tracing)
- Assist in diagnostics or security logging
- Be used for custom caching or CDN logic
Step-by-Step: Add Header in nginx
Step 1: Copy the nginx Template
First, copy the default Plesk template into a custom directory:
|
1 2 3 4 |
cd /usr/local/psa/admin/conf/templates mkdir -p custom/domain cp default/domain/nginxDomainVirtualHost.php custom/domain/ |
Step 2: Edit the Template
Open the copied file:
|
1 2 |
vi custom/domain/nginxDomainVirtualHost.php |
Locate the block that outputs header directives, such as:
|
1 2 3 4 5 6 7 |
<?php foreach ((array)$VAR->domain->physicalHosting->headers as list($name, $value)): ?> add_header <?=$VAR->quote([$name, $value])?>; <?php endforeach ?> <?php if ($VAR->server->xPoweredByHeader) : ?> add_header X-Powered-By PleskLin; <?php endif ?> |
Insert your custom header right after:
|
1 2 3 4 |
<?php /* CUSTOM HEADER START */ ?> add_header X-Hosted-By "ExampleHost" always; <?php /* CUSTOM HEADER END */ ?> |
Step 3: Rebuild nginx Configurations
|
1 2 |
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all |
Step 4: Restart nginx
|
1 2 |
systemctl restart nginx |
Step-by-Step: Add Header in Apache
Step 1: Copy the Apache Template
|
1 2 3 4 |
cd /usr/local/psa/admin/conf/templates mkdir -p custom cp default/server.php custom/ |
Step 2: Edit the Template
|
1 2 |
vi custom/server.php |
Look for the following section:
|
1 2 3 4 5 6 |
<?php if (!$VAR->server->webserver->proxyActive && $VAR->server->xPoweredByHeader) : ?> <IfModule mod_headers.c> Header add X-Powered-By PleskLin </IfModule> <?php endif ?> |
Insert the new header block immediately after:
|
1 2 3 4 |
<?php /* CUSTOM HEADER START */ ?> Header always set X-Hosted-By "ExampleHost" <?php /* CUSTOM HEADER END */ ?> |
Step 3: Rebuild Apache Configurations
|
1 2 |
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all |
Step 4: Restart Apache
|
1 2 |
systemctl restart apache2 # or `httpd` |
Verifying the Header
To confirm the header has been successfully applied:
|
1 2 |
curl -I https://example.com | grep X-Hosted-By |
You should see:
|
1 2 |
X-Hosted-By: ExampleHost |
Optional: Per-Domain Configuration via Plesk GUI
If you prefer to apply the header only to certain domains:
- Log in to the Plesk control panel
- Navigate to Domains → [Your Domain] → Apache & nginx Settings
- Under Additional nginx directives, add:
|
1 2 |
add_header X-Hosted-By "ExampleHost" always; |
- Under Additional Apache directives, add:
|
1 2 |
Header always set X-Hosted-By "ExampleHost" |
- Click Apply Changes
By customizing the Plesk templates, you can ensure consistency across all hosted sites while still allowing per-domain overrides when needed. This is a clean and manageable way to implement cross-server headers like X-Hosted-By, security headers, or custom CDN triggers.




