2

I'm running NGINX on Centos 8 and I can't get it to execute a perl script, it just keeps downloading the script.

I have several domains on this server and it runs php scripts and such fine.

I have installed perl on the server,

"This is perl 5, version 26, subversion 3 (v5.26.3) built for x86_64-linux-thread-multi"

I tried adding this server block to the conf.d file:

location ~ \.pl|cgi$ {
        try_files $uri =404;
        fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.cgi;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

Without this bit added to the server block, it simply downloads the file; with this bit added to the server block, I get a 502 bad gateway. So I'm sure something in there is incorrect.

I took it almost exactly from the PHP version of the bit, which looks like this:

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

Any ideas what I'm doing wrong? Thank you!!!

1 Answers1

0

You are trying to execute the Perl scripts with PHP by using the exact same FastCGI backend which you use for PHP. This will not work. The FastCGI backend for PHP will look for PHP code only and since there is none in the Perl scripts it will simply deliver the content the same it would do for HTML files.

Instead you need to have another FastCGI backend specifically for Perl. See here for an example on how to do this or one of the many other sites which cover this topic.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • I did see the first link but the instructions are for Debian and I can't sort out the RHEL/Centos versions of the packages listed. The issue I'm having finding info is basically all the tutorials I find online are for Ubuntu/Debian – Joshua Alayon Feb 01 '20 at 16:18
  • I did find this one, which looks like it uses RHEL/Centos since it uses yum, and completed the tutorial set to the letter but am still receiving a 502 bad gateway. [link](https://www.scalescale.com/tips/nginx/serve-perl-scripts-nginx/) – Joshua Alayon Feb 01 '20 at 17:00
  • @JoshuaAlayon: sorry, but it is impossible to say what you really did (and thus what you did wrong) based on your information. Please check the error.log of your nginx for what might have been failed. – Steffen Ullrich Feb 01 '20 at 17:22
  • 1
    GOT IT!!! It was SELINUX blocking it out. The instructions here worked, with the caveat that after all was done, I had to set chown nginx:nginx to the test file and folder: https://www.server-world.info/en/note?os=CentOS_8&p=nginx&f=6 I hope this helps anyone who ever runs into this issue! – Joshua Alayon Feb 01 '20 at 18:05