0

Im running CentOS 6.2, Nginx 1.2.3 following these Linode Instructions to get Perl to work with Nginx I've done everything upto the point of testing an actual Perl file. When I do this the browser says:

The page you are looking for is temporarily unavailable.
Please try again later. 

And my Nginx error-log shows the following:

2012/09/02 22:09:58 [error] 20772#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.102, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:8999", host: "192.168.1.10:81"

Im stuck at this point. Im not sure if it matters but I also have spawn-fcgi and php-fpm to serve up PHP files on this site, but that should be 100% seperate from the perl-fastcgi setup, different port, etc..

How can I troubleshoot this?

quanta
  • 51,413
  • 19
  • 159
  • 217
ProfessionalAmateur
  • 937
  • 6
  • 17
  • 27

3 Answers3

2
upstream: "fastcgi://127.0.0.1:8999"

returned the error

(111: Connection refused)

This means that nothing is actually listening on that port.

The most likely cause is that you didn't actually start the perl-fastcgi service.

/etc/rc.d/init.d/perl-fastcgi start
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • I ran the command, and nothing was returned to the command line and the webpage returns the same, however I dont see it started when I do a `service --status-all` either. Could I be missing something? – ProfessionalAmateur Sep 03 '12 at 06:10
  • Clearly the service didn't start for some reason, or started and then failed. Check the logs and check that you installed everything correctly. – Michael Hampton Sep 03 '12 at 06:21
  • Im not sure at this point what other logs to check. I do not see anything regarding perl-fastcgi in `/vatr/log/`? Where else cant I look? I get a status OK when I run the `perl-fastcgi start` – ProfessionalAmateur Sep 03 '12 at 16:17
1

Can you reach the fastcgi daemon via its public IP adress? At the moment you gave the localhost address in the nginx config, maybe it only listens on the public network interface.

j0nes
  • 955
  • 1
  • 12
  • 27
0

I believe the answer was a socket permission issue.

In my fastcgi-wrapper.pl there were the following two lines:

sub main {
    #$socket = FCGI::OpenSocket( "127.0.0.1:8999", 10 ); #use IP sockets
    $socket = FCGI::OpenSocket( "/var/run/nginx/perl_cgi-dispatch.sock", 10 ); #use UNIX sockets - user running this script must have w access to the 'nginx' folder!!
    $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket );
    if ($request) { request_loop()};
        FCGI::CloseSocket( $socket );
}

When I uncomment the TCPIP socket and comment the Unix Socket line the script works. I beleive this is because my NGINX user did not have the correct permissions to use /var/run/nginx/perl_cgi-dispatch.sock

I thought root was running nginx, but maybe it's not, Im not sure of that yet.

================================================

EDIT: The root user did have access to the socket, however my nginx configuration file was not pointing to the socket as @nickgrim mentioned below. I changed the site.conf to the following and the socket correctly ran the perl script (I also changed the fastcgi_wrapper.pl to use the socket again instead of the TCPIP):

location ~ \.pl|cgi$ {
        try_files $uri =404;
        gzip off;
        include /etc/nginx/fastcgi_params;
        #fastcgi_pass  127.0.0.1:8999;
        fastcgi_pass unix:/var/run/nginx/perl_cgi-dispatch.sock;
        fastcgi_index index.pl;
        fastcgi_param  SCRIPT_FILENAME  /srv/www/test1/$fastcgi_script_name;
    }
ProfessionalAmateur
  • 937
  • 6
  • 17
  • 27
  • it's almost certain that the nginx process runs as the nginx user, at least, it does in the official nginx source tree and on Fedora. nginx does not normally start processes for origin servers (unlike many other http servers, eg apache); the interpreter should be started with the same mechanism used to start nginx (eg, upstart/systemd) – SingleNegationElimination Sep 04 '12 at 15:25
  • It looks like nginx is run by root based on the `pa aux` command -> `root 20771 0.0 0.0 7272 668 ? Ss Sep02 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf` There are other nginx worker processes that are run by the user `nginx` though... Hrm – ProfessionalAmateur Sep 04 '12 at 16:02
  • 1
    Unless there was an edit I missed, I don't think it's to do with nginx not having permission to read the filesystem-socket - it wasn't looking for it in the first place. – nickgrim Sep 04 '12 at 16:57
  • @nickgrim - Should I have changed my nginx site conf file from `fastcgi_pass 127.0.0.1:8999;` to `fastcgi_pass /var/run/nginx/perl_cgi-dispatch.sock`? Is this what you meant by it not looking for it in the first place? – ProfessionalAmateur Sep 04 '12 at 17:13
  • 1
    Yes, except the line should be `fastcgi_pass unix:/var/run/nginx/perl_cgi-dispatch.sock`. Have a read of [this example](http://wiki.nginx.org/PHPFcgiExample). – nickgrim Sep 04 '12 at 17:17
  • @nickgrim: Thank you that did the trick. Appreciate it. – ProfessionalAmateur Sep 04 '12 at 17:34