Method to create a proxy block in nginx using a server template

OS type and version Rocky Linux 9.1
Webmin version 2.021
Usermin version 1.861
Virtualmin version 7.7
Theme version 20.21
Package updates All installed packages are up to date

I am trying to do is insert a custom field into my nginx server block when a new virtual server is created.

My use case is a node service that is managed by pm2, where each virtual server is assigned a new node port (e.g. starting from port 3000).

The proxy entry for each server in nginx looks like this:

location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;

So what I need is the ability to set the port number for proxy_pass. If I create a ‘Custom Field’ like this:

This creates an input box when editing a virtual server:

I’ve tried to add this field using $FIELD_nodeport in the plugin conf for Nginx, as follows:

However when I create a new virtual server, I get the following error:

Applying Nginx configuration ..
.. configuration is invalid : nginx: [emerg] unknown "field_nodeport" variable nginx: configuration file /etc/nginx/nginx.conf test failed

So my question is: how do I get the value of nodeport into the nginx server block (as it looks like I can’t use the additional nginx route, unless I’m doing it wrong!)?

I’m guessing a bash script :slight_smile: