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

**URL:** <https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829>\
**Category:** NGINX\
**Created:** [July 31, 2015, 2:56pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829 "2015-07-31T14:56:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [July 31, 2015, 2:56pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/1 "2015-07-31T14:56:02Z")

</div>

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:

> **[Perl + fcgi + nginx - what am I doing wrong?](https://forum.nginx.org/read.php?2,260678,260678#msg-260678)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [July 31, 2015, 4:59pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/2 "2015-07-31T16:59:18Z")

</div>

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:

> **[Re: Perl + fcgi + nginx - what am I doing wrong?](https://forum.nginx.org/read.php?2,260678,260681#msg-260681)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [July 31, 2015, 6:01pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/3 "2015-07-31T18:01:14Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [July 31, 2015, 8:19pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/4 "2015-07-31T20:19:44Z")

</div>

Hi,

On 31 July 2015 at 07:55, youradds [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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:  
> [http://forum.nginx.org/read.php?2,260678,260678#msg-260678](http://forum.nginx.org/read.php?2,260678,260678#msg-260678)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

~ Happy install !

Erick.

* * *

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

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [July 31, 2015, 7:52pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/5 "2015-07-31T19:52:15Z")

</div>

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](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](http://pastebin.com/QMHKGkJX)  
NEW ONE: [fastcgi\_param QUERY\_STRING $query\_string;fastcgi\_param REQUEST\_METHOD - Pastebin.com](http://pastebin.com/G72Ds9aA)

Hopefully that answers everything 🙂

Cheers

Andy

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,260678,260684#msg-260684](http://forum.nginx.org/read.php?2,260678,260684#msg-260684)

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [July 31, 2015, 8:55pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/6 "2015-07-31T20:55:24Z")

</div>

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 😉

Cheers

Andy

Posted at Nginx Forum:

> **[Re: Perl + fcgi + nginx - what am I doing wrong?](https://forum.nginx.org/read.php?2,260678,260687#msg-260687)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [July 31, 2015, 9:00pm UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/7 "2015-07-31T21:00:05Z")

</div>

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:

> **[Re: Perl + fcgi + nginx - what am I doing wrong?](https://forum.nginx.org/read.php?2,260678,260688#msg-260688)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![youradds](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f1d935/32.png) [@youradds](https://www.ruby-forum.com/u/youradds)\
**Post date:** [August 1, 2015, 12:23am UTC](https://www.ruby-forum.com/t/perl-fcgi-nginx-what-am-i-doing-wrong/242829/8 "2015-08-01T00:23:59Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
