Warm tip: This article is reproduced from stackoverflow.com, please click
centos nginx perl fastcgi centos8

NGINX not executing perl scripts?

发布于 2020-04-10 10:19:38

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!!!

Questioner
Joshua Alayon
Viewed
103
Steffen Ullrich 2020-02-01 23:59

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.