Nginx – Perl and nginx configuation

nginxperl

I'm trying to get the latest nginx running alongside Perl. I know Perl itself is installed, as I can run test.cgi perfectly from the command line. However, when trying to run from the browser I get a "502 Bad Gateway" error.

Below is my current config:

server {
    listen   80;
    server_name mysite.net www.mysite.net;
    access_log /srv/www/mysite.net/logs/access.log;
    error_log /srv/www/mysite.net/logs/error.log;
    root /srv/www/mysite.net/www;

    location / {
        root   /srv/www/mysite.net/www;
        index  index.html index.htm index.php;
    }

    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/mysite.net/www$fastcgi_script_name;
    }

    location ~ \.cgi$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME /srv/www/mysite.net/cgi-bin$fastcgi_script_name;
    }

    location ~ /\.ht {
            deny all;
    }
}

Any suggestions? I've got everything else I need working (PHP, nginx itself, SFTP etc), but I can't for the life of me get nginx and Perl to play nice.

Here is the tutorial I have followed to get up to this point:

https://www.linode.com/docs/websites/nginx/nginx-and-perlfastcgi-on-ubuntu-12-04-lts-precise-pangolin

As far as I'm aware, I have done exactly what it says.

Best Answer

Ok, not too sure what it was I did to fix it - but its running now

/var/run/fcgiwrap.socket was CHMOD 744 I set it to 666, and then rebooted nginx. That seems to have done the trick. Here is the final config I was using, in the hope that it will help someone else having a similar problem:

server {
    listen   80;
    server_name mysite.net www.mysite.net;
    access_log /srv/www/mysite.net/logs/access.log;
    error_log /srv/www/mysite.net/logs/error.log;
    root /srv/www/mysite.net/www;

    location / {
        root   /srv/www/mysite.net/www;
        index  index.html index.htm index.php;
    }

    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/mysite.net/www$fastcgi_script_name;
    }


    location ~ \.cgi$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME /srv/www/mysite.net/www/cgi-bin/$fastcgi_script_name;
    }


}