0

Having trouble understanding how to correctly use FastCGI processes with NGINX. Unlike Apache, NGINX does not automatically spawn FCGI processes. So I first apt-get fcgiwrap spawn-fcgi.

I spawned a fcgi process by using the command

sudo spawn-fcgi -f /usr/sbin/fcgiwrap -s /tmp/fcgiwrap.socket

But I'm still getting a 502 Bad Gateway in my browser and the following error in my NGINX error log

*68 connect() to unix:/tmp/fcgiwrap.socket failed (13: Permission denied) while connecting to upstream client xxx.xxx.xxx.xxx, server: git.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/fcgiwrap.socket:", host: "git.example.com"

The cgi app is gitweb and I have my NGINX conf as follows:

server {
  listen 443 ssl;
  server_name git.example.com;

  location /index.cgi {
    root /usr/share/gitweb;
    include fastcgi_params;
    gzip off;
    fastcgi_param SCRIPT_NAME $uri;
    fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
    fastcgi_pass unix:/tmp/fcgiwrap.socket;
  }
  location / {
    root /usr/share/gitweb;
    index index.cgi;
  }

  ssl_certificate /.../fullchain.pem;
  ssl_certificate /.../privkey.pem;


}

Follow up question: if I want to create an init script for spawning fastcgi like NGINX example here, do I only need to change BIND=/tmp/fcgiwrap.socket and PHP_CGI=/usr/sbin/fcgiwrap ?

1
  • You spawned a process under root. Chances are, nginx is running under another user (www-data) so it can't access the socket
    – esoroka
    Nov 6, 2019 at 18:13

1 Answer 1

0

For anyone with the same problem. I initially just created a file called fcgiwrap.socket and chown www-data fcgiwrap.socket, chgrp www-data fcgiwrap.socket, chmod g+x fcgiwrap.socket. What I didn't realize is whenever you use spawnfcgi to spawn a fastcgi process, it kills any previous socket and creates a new one. For me, because I wasn't under root I had to use sudo to run spawnfcgi

sudo spawnfcgi -a /usr/sbin/fcgiwrap -s /tmp/fcgiwrap.socket`

This will, like I said, create a new socket and, more importantly, under root. So just rerun chmod,chgrp,chown AFTER spawning a fastcgi process and you should resolve permission denied error.

You must log in to answer this question.

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