I can't setup fcgi+unix with nginx

I tried with just http+unix configuration and I’m able to set the proxy reverse in nginx to get it working.

However, any time I try fcgi+unix, I always get a connection reset (petition is not forwarded to gitea as I see in the logs), I cannot get the proper configuration in nginx neither I can find any example on the Internet.

Do any of you have a working nginx configuration for fcgi+unix so I can take it as an example?

Part of nginx.conf of one of my attempts:

location / {
   proxy_set_header    Host                $host;
   proxy_set_header    X-Real-IP           $remote_addr;
   proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
   proxy_set_header    X-Forwarded-Proto   $scheme;
   proxy_pass http://unix:/run/gitea/gitea.sock;
   #fastcgi_pass unix:/run/php-fpm/giteaphp.sock;
  }

#location ~ \.php$ {
#	    try_files $uri =404;
#	    fastcgi_pass unix:/run/php-fpm/giteaphp.sock;
#}

I think you have to change
proxy_pass http://unix:/run/gitea/gitea.sock;
And turn it into
proxy_pass unix:/run/gitea/gitea.sock;
Let me know if that works.

Not working, nginx throws an error about an invalid URL prefix. Proxy_pass needs that http:// while fastcgi_pass is the one starting with unix. And I tried with fastcgi_pass without success.

Found the issue

I should not use proxy_pass, but fastcgi_pass instead and I was missing the include fastcgi.conf

location / {
    include fastcgi.conf;
    proxy_http_version 1.1;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-Ssl     on;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    fastcgi_pass unix:/run/gitea/gitea.sock;
  }

This works already, plus the following in gitea app.ini

HTTP_PORT        = 0
PROTOCOL	= fcgi+unix
HTTP_ADDR	= /run/gitea/gitea.sock

1 Like