Error Code: 20 - I guess due to nginx template config

Hi! I’m trying to update the nginx template for a given domain, and when changing the Proxy Template in the admin panel, I get:

Error Code: 20

The template I’m editting is the exact copy of the default.tpl and .stpl with a few changes so I can handle different server names, differently

I perform 2 edits on those files. The second edit it what throws the Error Code 20.

First, let me introduce it. I have 2 domains: domain-one.com and domain-two.com on the same VPS. I have only one domain in the Hestia admin panel, which is domain-one.com. And in the aliases section of it I add domain-two.com so the SSL certificate would be valid for it as well.

The default NGINX config handles both in the same way. But I’d like to redirect domain-one to port 8888 and domain-two to port 9999. So I create a new template from the default one (name my-template) and I have 2 server blocks, one with server_name equal to domain-one.com and the other with server_name equal to domain-two.com

Also the first one has proxy_pass to port 8888 and the other to 9999.

In the admin I set that template to the site and everything works fine. Navigating to domain-one.com gets me into the service running on port 8888 and navigating to domain-two.com, to the one on port 9999 as expected.

Now I’d like to modify the template to also allow a different hostname on domain-two. So:

domain-one.com ----> port 8888
domain-two.com ----> port 9999
myhost.domain-two.com ----> port 7777

So I added a new server bock to the template, with server_name equal to myhost.domain-two.com and proxy_pass to port 7777.

Now I get to the admin panel again, change the Proxy Template to the default one, save it, and then back to my-template and I can not save it because I get the Error Code 20. And I don’t know what it means. If I delete the latest added server block of the template, the error is gone. So I guess there’s something wrong with my configuration in the template.

Thank you!

Proxy Extensions should be your port number.

@eris thank you for your response… I’m sorry I do not understand what you mean. I’ll paste the full .tpl template I have (the .stpl) it’s very similar.

What I do not understand is how NGINX would know that I want to go to port 7777 if I replace it with %proxy_extensions%

# DOMAIN ONE
server {
    listen      %ip%:%proxy_port%;
    server_name domain-one.com www.domain-one.com;

    include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;

    location / {
        proxy_pass      http://%ip%:8888;
        location ~* ^.+\.(%proxy_extensions%)$ {
            root           %docroot%;
            access_log     /var/log/%web_system%/domains/%domain%.log combined;
            access_log     /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:8888;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/%domain%/nginx.conf_*;
}

# DOMAIN TWO
server {
    listen      %ip%:%proxy_port%;
    server_name domain-two.com www.domain-two.com;

    include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;

    location / {
        proxy_pass      http://%ip%:9999;
        location ~* ^.+\.(%proxy_extensions%)$ {
            root           %docroot%;
            access_log     /var/log/%web_system%/domains/%domain%.log combined;
            access_log     /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:9999;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/%domain%/nginx.conf_*;
}



# DOMAIN TWO - myhost
server {
    listen      %ip%:%proxy_port%;
    server_name myhost.domain-two.com;

    include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;

    location / {
        proxy_pass      http://%ip%:7777;
        location ~* ^.+\.(%proxy_extensions%)$ {
            root           %docroot%;
            access_log     /var/log/%web_system%/domains/%domain%.log combined;
            access_log     /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:7777;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/%domain%/nginx.conf_*;
}

If I remove the last server block, everything works fine. But If I leave it I get an error code 20 as said before.

Additional information: as I can see in the repo you point me and other colleague recommend, I should replace:

proxy_pass      http://%ip%:8888;

with (use localhost on proxy pass)

proxy_pass      http://127.0.0.1:8888;

This is my first time dealing with NGINX, I’d appreciate if you can help me out here. Thank you very much!

I’m sorry to bother again… could anyone take a look at this, please? I can not make it work yet

1st create for each domain different templates files

Enable the templates and run nginx -t to test the templates it should show the errors you have

Thank you again @eris !

With the help of

nginx -t

I manage to find the error and solve it

“proxy_pass” cannot have URI part in location given by regular expression

Thank you very much!

Please share your both template files.