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?

3 Answers 3

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
3
  • 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? Sep 3, 2012 at 6: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. Sep 3, 2012 at 6: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 Sep 3, 2012 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.

1
  • Everything is running internally on my local network for now, Im just tinkering to get nagios working with nginx for my home network. Sep 3, 2012 at 6:11
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;
    }
6
  • 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) Sep 4, 2012 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 Sep 4, 2012 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 4, 2012 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? Sep 4, 2012 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.
    – nickgrim
    Sep 4, 2012 at 17:17

You must log in to answer this question.

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