virtualmin / virtualmin-nginx

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

Nginx improvements #36

Closed iliajie closed 2 years ago

iliajie commented 2 years ago

Jamie, I was running more tests today on Nginx module and found few bugs:

  1. When PHP execution mode is set to Disabled, PHP files where downloaded instead of shown as text due to incorrect mime type. Fixed on this commit in this PR - https://github.com/virtualmin/virtualmin-nginx/commit/cf6a0ece77bfbc43eeae2b1759c0d9b82fb8290e
  2. Even though FCGIWrap systemd unit is setup correctly, the scripts are not executed (i.e. under /cgi-bin directory) and an error always displayed: image
  3. If a template has Disabled set for PHP execution mode then still a newly created website has FCGId setup by default (when should be Disabled as defined on the template)

Can you please pull this branch and check in a fix for #2 and #3 please? Also, check if #1 looks good to you as it works perfectly fine for me.

jcameron commented 2 years ago

Regarding (2), which Linux distribution did you see this on? And did anything useful get written to logs/error_log ?

iliajie commented 2 years ago

That was AlmaLinux. I don't remember exactly about errors in Nginx logs. But this error usually means that either a service isn't running or something is misconfigured under /cgi-bin location in a server config.

jcameron commented 2 years ago

Did you only see this on AlmaLinux?

iliajie commented 2 years ago

Did you only see this on AlmaLinux?

I see it on both Alma 9 and Ubuntu 22.04 with Nginx.

However, I just found a "problem", as when you run scripts under Nginx it returns damn super confusing error (502 bad gateway), unless you don't print first print "Content-Type: text/html\n\n"; or even print " \n\n"; works which makes it even more ridiculous.

i.e. test.cgi and fcgiwrap with Apache and the following works:

#!/usr/bin/perl

print "Hello World";

However, under Nginx it prints misleading error in ~/logs/fcgiwrap.log:

Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?

.. which makes absolutely no sense! It took me some time to understand what was really wrong. However, just "sending headers" with print "Content-Type: text/html\n\n"; makes it work with Nginx as well:

#!/usr/bin/perl

print "Content-Type: text/html\n\n";
print "Hello World";

.. and more ridiculous this works too:

#!/usr/bin/perl

print " \n\n";
print "Hello World";

.. but why? And isn't that sick that the error message produced is so misleading? I know it's not our problem but still.

jcameron commented 2 years ago

That's kind of expected - all CGI scripts must output proper headers. If not, the fcgiwrap server probably just fails to process the output and returns an error to Nginx.

jcameron commented 2 years ago

As for issue #3, it should be fixed by https://github.com/virtualmin/virtualmin-nginx/commit/7e65268da6a18ede469bba9c791417ab42511020

iliajie commented 2 years ago

That's kind of expected - all CGI scripts must output proper headers.

Yes, yes I'm aware of that but the error message is deceptive!

As for issue https://github.com/virtualmin/virtualmin-nginx/issues/3, it should be fixed by https://github.com/virtualmin/virtualmin-nginx/commit/7e65268da6a18ede469bba9c791417ab42511020

That works, thanks!