• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Question Plesk XML API to change nginx directives

chapterjason

New Pleskian
Hey,

I currently working on a PAAS for NodeJS and PHP Applications that run in Docker.

Currently im stuck a bit while try to create the proxy_pass in nginx, I already modified my vhost template that the proxy_pass in the Additional directives will take place.

But I don't know how to set this via the XML API.
 
Perhaps this link can be of use:

  • The additional-nginx node is optional. It specifies additional directives for nginx. Data type: string.
 
@Rasp Thanks for your reply.

Your link shows a way to add this for all domains on the server. What i would like is to use it on a per domain basis.

I'm using the php api client library to do a request like:
PHP:
$this->client->request([
            'site' => [
                [
                    'set' => [
                        'filter'  => [
                            'name' => 'my-domain.com'
                        ],
                        'values' => [
                            'hosting' => [
                                'vrt_hst' => [
                                    'property' => [
                                        [
                                            'name' => 'additional-nginx',
                                            'value' => 'my-value'
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ])

I have tried both additional-nginx-settings and additional-nginx. It returns a "status": "ok" but when i go to plesk and look at the "Additional nginx directives" under the domain the field is empty. Also doing a quick cat /var/www/vhosts/system/my-domain.com/conf/vhost_nginx.conf shows an empty file.

Is this possible through the API?
 
Hmmm, I could not find anything related in the API documentation. Neither does the Plesk CLI seem to have a similar feature. Not 100% sure, but I am afraid it isn't possible.

I did found this article however. Which looks interesting as workaround.
 
@Kaspar Thank you for your provided article. Unfortunately, that only resolves the case when you have access to root. Otherwise, it is not possible to use plesk cli, as for managed servers.

The approach through XML API would be crucial to automate nginx configuration for specific domains. It seems like this is not supported.
 
Yes, root privileges are needed to make any adjustments to a domains additional nginx directives outside of the GUI. If I am not mistaken there are no plans at Plesk to further extend or update the XML API and the REST API is just meant for simple operations. So my previous suggestion is probably the most feasible option. Another option might be to develop your own Plesk extension to allow for a more customized nginx configuration on a per domain basis.
 
@Kaspar Thank you for your provided article. Unfortunately, that only resolves the case when you have access to root. Otherwise, it is not possible to use plesk cli, as for managed servers.

The approach through XML API would be crucial to automate nginx configuration for specific domains. It seems like this is not supported.

@tertek,

It should never be supported, otherwise the attack surface would increase considerably by allowing (too much) access - code injection would be possible.

Nevertheless, I do understand your demand for "automation" of Nginx configuration.


At this moment, there are two methods to "automate" Nginx configuration.

The first method is to use Plesk custom templates and that works like charm, with one issue : the customization will always result in error notifications (that can be ignored in 98 out of 100 cases).

The second method is to create a script (bash or something else) that is run by a cronjob on a scheduled time : it allows you to "inject" specific Nginx config into the config of specific domains, but it does require some root access.

I am pretty sure that the "root access challenge" can be worked around with plain old FTP, but I would not recommend it at all.


One should always recall that Nginx configuration is not designed to be dynamic.

It essentially is static config that allows Nginx to perform and exhibit dynamic behavior.

Stated differently, your goals and objectives might not fit the optimal usage of Nginx config and/or your use-cases might require some other solution.


For instance, "automating" Nginx directives in a couple of domains is not a good idea.

The custom Nginx config should be of that nature and excellence that it would not have to change, never.

So, a simple addition of a config LINES via Plesk GUI should suffice for a very long period.


However, there are some use-cases where the Nginx config is created in a dynamic fashion.

For instance, the creation of dynamic blocklists (with a combination of Fail2Ban and Nginx) creates a static (not dynamic) Nginx file that changes each time an IP has been added or removed - this custom Nginx config file simply requires a task-based reload of Nginx config (and that is easily done in Plesk GUI).


Moreover, there are some use-cases that require server-wide customization.

In this case, the server-wide customization can be achieved with Plesk custom templates OR plain old static Nginx config files, depending on the use-case that is applying and/or depending on the objectives.


In general, Nginx is rather versatile and "Nginx automation" should not be necessary.

In addition, Plesk custom templates are only necessary in those cases where Plesk default templates fail miserably (and that happens).


So, I am not entirely sure why you would go the length of Plesk extension development (which will not result in you achieving your goals) and I am certainly not sure why you want to automate Nginx.

Could you elaborate on that?


Kind regards.....
 
Back
Top