2

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.

1 Answer 1

0

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;
    }


}
4
  • 1
    I would fix the permissions issue so that the permissions would be tighter. For example, put Perl and Nginx both into the same group so you can use 660 permissions on the socket. Otherwise any user can access the socket, which is not optimal from security standpoint. Commented Jul 17, 2015 at 19:43
  • Thanks for the feedback Tero. The server is actually a Linode "node" ... so only has my one domain on it - so probably don't need to worry about that :) Commented Jul 17, 2015 at 20:35
  • Well, depends on the other servies running on the node and their permissions. Commented Jul 17, 2015 at 21:40
  • Should just be pretty basic stuff: Perl, nginx, FastCGI, SFTP services etc. Commented Jul 18, 2015 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .