Perl + fcgi + nginx - what am I doing wrong?

Hi,

I’ve already got a live + dev site running under nginx and perl (with
fcgi),
but I can’t for the life of me work out why its not working this time
around. I’ve setup a new dev server. I wont bore you with all of the
details, but suffice to say I have installed (via apt-get);

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install nginx
sudo apt-get install php5-cli php5-cgi spawn-fcgi php-pear
sudo apt-get install mysql-server php5-mysql
sudo apt-get install fcgiwrap

The OS is Debian 8.1.

I have then configured my site, using:

server {

    listen   80;

    server_name site.net.net www.site.net.net;
    access_log /srv/www/site.net.net/logs/access.log;
    error_log /srv/www/site.net.net/logs/error.log;
    root /srv/www/site.net.net/www;

 location / {
        index  index.html index.htm;
    }

  location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME

/srv/www/site.net.net/www$fastcgi_script_name;
}

  location ~ \.cgi$ {
            try_files $uri =404;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
            fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME

/srv/www/site.net.net/www/cgi-bin/$fastcgi_script_name;
}

}

I’ve sym-linked the config files into sites-enabled, so that its visible
on
nginx. I then rebooted nginx, and tried:

index.html - works fine
index.php - works fine
index.cgi - 403 error

I managed to fumble my way through it last time, but I can’t figure out
what
I did different (I know it was a real pig to get configured the first
time
around)

Any suggestions from the experts?

(appologies for the formatting of this post - can’t figure out how to do
markup?)

TIA

Andy

Posted at Nginx Forum:

FWIW - this is what I get when I run it via SSH:

root@server:/var/run# perl /srv/www/site.net/www/index.pl
Content-Type: text/html

FOO

…yet I get a 403 in the browser (and nothing in the site error_log)

TIA

Posted at Nginx Forum:

On Fri, Jul 31, 2015 at 08:55:44AM -0400, youradds wrote:

Hi there,

I’ve already got a live + dev site running under nginx and perl (with fcgi),
but I can’t for the life of me work out why its not working this time
around.

What is shown when you “diff” the working old nginx.conf and the failing
new nginx.conf?

Do the old and new use the same fastcgi server? Are there any
differences
in the fastcgi server config?

  location ~ \.cgi$ {
            try_files $uri =404;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
            fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME

/srv/www/site.net.net/www/cgi-bin/$fastcgi_script_name;
}

index.html - works fine
index.php - works fine
index.cgi - 403 error

What file on your filesystem do you want the fasctcgi server to process
when you request this index.cgi? – your server layout.

What SCRIPT_FILENAME value(s) does nginx send to your fastcgi server? –
nginx debug logs, or watch the traffic.

(Does your fastcgi server even use SCRIPT_FILENAME? – your fastcgi
server documentation.)

Is SCRIPT_FILENAME set in your /etc/nginx/fastcgi_params?

f

Francis D. [email protected]

Hi,

On 31 July 2015 at 07:55, youradds [email protected] wrote:

sudo apt-get install php5-cli php5-cgi spawn-fcgi php-pear

        try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
            fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME

/srv/www/site.net.net/www/cgi-bin/$fastcgi_script_name;
}

AFAIK, path before $fastcgi_script_name should not end with /

Log didn’t say anything in particular? error 403 where comes? 403 means
forbidden, perhaps socket which your are running has not been started
with
same permissions as Nginx does/can.

Running fcgi manually through that socket could bring you more clues
about
whats happening/wrong with the communication between Nginx and fcgi

what
Andy

Posted at Nginx Forum:
Perl + fcgi + nginx - what am I doing wrong?


nginx mailing list
[email protected]
nginx Info Page

~ Happy install !

Erick.


IRC : zerick
Blog : http://zerick.me
About : Erick Ocrospoma Lazo | about.me
Linux User ID : 549567

Hi Fancis,

Thanks for the reply!

What is shown when you “diff” the working old nginx.conf and the failing
new nginx.conf?

Not a huge amount tbh. The live one has:

pid /var/run/nginx.pid;

and new dev has:

pid /run/nginx.pid;

New one has:

SSL Settings

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

…extra.

…and the old one has this extra (all commented out, mind);

gzip_types text/plain text/css application/json

application/x-javascript
text/xml application/xml application/xml+rss text/javascript;

nginx-naxsi config

Uncomment it if you installed nginx-naxsi

#include /etc/nginx/naxsi_core.rules;

nginx-passenger config

Uncomment it if you installed nginx-passenger

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

Do the old and new use the same fastcgi server? Are there any differences
in the fastcgi server config?

Both the same by the looks of it:

root@steamdev2:~# service fastcgi --version
service ver. 0.91-ubuntu1

root@steampunkjlinode:~# service fastcgi --version
service ver. 0.91-ubuntu1

Do the old and new use the same fastcgi server? Are there any differences
in the fastcgi server config?

Do you mean the etc/init.d/fcgiwrap file? There were a few differents in
it
(mostly comments). I tried copying the same one over from live, but
didn’t
seem to make a difference

What file on your filesystem do you want the fasctcgi server to process
when you request this index.cgi? – your server layout.

The layout is:

/srv/www/site.net/logs/
/srv/www/site.net/www/
/srv/www/site.net/www/cgi-bin

The .cgi/.pl stuff is all going to be in /cgi-bin - but for testing
purposes, I’ve just stuck it at root level (so I can try out and see if
I
can get it working at the most basic level)

The script in question would be found /srv/www/site.net/www/index.cgi,
and I
would expect it to work/run at http://site.net/index.cgi

With regards to /etc/nginx/fastcgi_params settings - here are the
values of
them:

LIVE (working) ONE: fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_ - Pastebin.com
NEW ONE: fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD - Pastebin.com

Hopefully that answers everything :slight_smile:

Cheers

Andy

Posted at Nginx Forum:

Hi,

Aaaaah now I feel like a total muppet!

I had:

fastcgi_param SCRIPT_FILENAME
/srv/www/site.net/www/cgi-bin/$fastcgi_script_name;

but it wasn’t in the cgi-bin!!!It should have been:

fastcgi_param SCRIPT_FILENAME
/srv/www/site.net/www/$fastcgi_script_name;

Reboot it, and it works fine now., That’d be whyit was 403’ing… as it
couldn’t find the file. Duh!

Thanks for sticking through this with me. I’ve been battling that for
hours.
Always so simple when you know the answer :wink:

Cheers

Andy

Posted at Nginx Forum:

haha yup - that was it! Just tweaked the config for it, and it works
perfectly. Still got some fun and games to do with the modules that need
installing- but at least I can finally access it from the browser, to
test
it all.

Thanks again!

Andy

Posted at Nginx Forum:

On Fri, Jul 31, 2015 at 02:55:02PM -0400, youradds wrote:

Hi there,

Good that you found and fixed the problem.

couldn’t find the file. Duh!
Note, you have

try_files $uri =404;
fastcgi_param SCRIPT_FILENAME
/srv/www/site.net.net/www/cgi-bin/$fastcgi_script_name;

The first line says “return 404 unless the file $document_root$uri
exists”.

In general, if the second line does not also refer to exactly the
filename
$document_root$uri, you should suspect a problem.

(It can validly refer to a different filename, but probably only where
the fastcgi server is inside a chroot area.)

When you come to use the cgi-bin directory, you’ll want to be aware of
that.

Cheers,

f

Francis D. [email protected]