Using Plesk SDK API, an extension can make changes to the web server
configuration.
- Class
pm_Hook_WebServer
allows to describe custom directives for domains to be added to the
configuration files. - Class
pm_WebServer
is used to instruct the web server to update the configuration for
the specified domain.
Note: The following sample project is provided by Plesk to illustrate how
an extension can add changes to the web server configuration files:
https://github.com/plesk/ext-web-server.
Adding Custom Configuration
The following methods of the class
pm_Hook_WebServer
are used to describe custom directives introduced by the extension into
the web server configuration files:
-
getDomainApacheConfig(pm_Domain $domain)
- returns the string
which will be added to the Apache configuration as a
<VirtualHost></VirtualHost>
custom directive. -
getDomainNginxConfig(pm_Domain $domain)
- returns the string
which will be added to nginx configuration as a{...}
custom
directive when nginx is used as the main web server. -
getDomainNginxProxyConfig((pm_Domain $domain)
- returns the
string which will be added to nginx configuration as a{...}
custom directive when nginx is used in proxy mode. -
getDomainIisConfig(pm_Domain $domain)
- returns XML as a string
which will be added to the Plesk IIS configurator.
Every time a domain is reconfigured, these methods will be called.
class Modules_WebServer_WebServer extends pm_Hook_WebServer
{
public function getDomainApacheConfig(pm_Domain $domain)
{
return '# Apache config for domain: ' . $domain->getName();
}
public function getDomainNginxConfig(pm_Domain $domain)
{
return '# Nginx config for domain name: ' . $domain->getName();
}
}
Updating Domain Configuration
Method
pm_WebServer::updateDomainConfiguration()
is used to immediately update the specified domain configuration. For
example, this can be done when some additional service was activated on
that domain by the extension.
$webServerManager = new pm_WebServer();
$webServerManager->updateDomainConfiguration(new pm_Domain(1));