virtualmin / virtualmin-nginx

Virtualmin plugin to allow use of nginx web server for virtual domain hosting
GNU General Public License v3.0
35 stars 13 forks source link

unexpected fastcgi_read_timeont parameter appears on line 63 or 66 of the host nginx configuration #58

Open sbruimen opened 1 year ago

sbruimen commented 1 year ago

Hello!

We use virtualmin api to create domains with custom template and installation script configured. We use our custom post-installation script to install our web service (similar to installing WordPress product for example)

The problem is: after running the post-installation script from template and modifying the nginx configuration, on line 63 earlier, and line 66 today, an additional line "fastgi_read_timeout 60" unexpectedly appears o_O

After we noticed this bug, we counted the lines and left empty and commented lines 63-66 in our nginx config template and removed from nginx confiuration the original fastgi_read_timeout parameter to avoid parameter duplication. So it allows the system to work, but does not solve the bug.

The installation script executes after creating the domain and reads the nginx configuration file and replaces the typical PHP location section in it, adds configuration sections (about 150 lines) adapted for the correct operation of our web service. The configuration is correct and the web services on it work successfully, it is being validated by the nginx successfully.

We have a suspicion that some parsing mechanisms of either the virtualmin kernel or the nginx plugin do not work correctly. Please tell us in which direction we can to dig deeper.

Environment: OS Debian Linux 11 Webmin 2.0.21 Virtualmin 7.7 (LEMP bundle) Nginx website 2.30 Nginx ssl website 1.19 nginx hosts configurations are stored in different "sites-enabled" files.

jcameron commented 1 year ago

So is the issue that your template contains fastgi_read_timeout already and Virtualmin is adding it again unnecessarily?

sbruimen commented 1 year ago

no, the problem is different.

The algorithm: 1) calling via API a request to create a domain "D" (virtual host) with a certain template parameter "T". https://www.virtualmin.com/documentation/developer/cli/create_domain/

At this point, a valid nginx configuration file is created, which already includes the fastgi_read_timeout parameter.

2) Autostart within the "T" template of my custom perl web application installation script "S". https://www.virtualmin.com/documentation/developer/scripts/

In script "S": -open the nginx host "D" configuration file -delete the entry existing of the fastcgi_read_timeout parameter in it. (If i dont do it, the duplication error appears) -replace the typical location section with my custom one, at the same time, I specifically leave this insert in the region of 63-66 lines:

location ~ "\.php(/|$)" {
fastcgi_pass mysocket-php:9000;
#that strings are for bug
#63
#64
#65
#66
         include fastcgi_params;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param QUERY_STRING $query_string;
}

-save this file.

3) Next, the installation script (2) and the virtual host creation command (1) are completed

After that, in fact, on line 66 of the nginx host configuration, a line suddenly appears with the fastgi_read_timeout parameter. If i remove the commented lines 63-66, then this bug will replace the line at position 66, for example fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; and the app won't work.


Maybe opening the nginx configuration file from a install script and replacing some of the lines in it is not correct, should I use some special functions? But no information found how to do it in correct way.

jcameron commented 1 year ago

Ah, I think Virtualmin is getting confused by the modification of the Nginx config by an external process in the middle of domain creation.

Why not instead do the customization at the end of the creation process, via a post-creation script? See https://www.virtualmin.com/documentation/developer/prepost/