I have a small problem with configuring Mercurial to work with nginx using unix sockets on raspberry pi. When accessing http://myip/hg via web browser, I get 502 Bad Gateway error and error.log displays following error:

connect() to unix:/srv/hg/mercurial.sock failed (111: Connection refused) while connecting to upstream, client: myPCIP, server: localhost, request: "GET /hg/ HTTP/1.1", upstream: "fastcgi://unix:/srv/hg/mercurial.sock:", host: "myServerIP"

I can't seem to figure out what is wrong. Can you please help?

Oh and here is my default web site config:

server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        # mercurial setup
        location /hg {
                root /srv/hg/;
                auth_basic "Secure Login";
                auth_basic_user_file /srv/hg/hgusers;
                fastcgi_pass unix:/srv/hg/mercurial.sock;
                fastcgi_param SCRIPT_FILENAME /srv/hg/$fastcgi_script_name;
                fastcgi_param PATH_INFO $uri;
                fastcgi_param REMOTE_USER $remote_user;
                fastcgi_param DOCUMENT_ROOT /srv/hg/;
                include fastcgi_params;
                client_max_body_size 20M;

                fastcgi_param QUERY_STRING $query_string;
                fastcgi_param REQUEST_METHOD $request_method;
                fastcgi_param CONTENT_TYPE $content_type;
                fastcgi_param CONTENT_LENGTH $content_length;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass php5-fpm-sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                include fastcgi_params;
  • 1
    I think it should be opened, as in other linux distributions, the mercurial server installation probably wouldn't depend on php-fpm but in wsgi or other implementation. besides, having a well documented mercurial installation of mercurial with raspberry pi would be a very good content on the site. Apr 21, 2015 at 16:31
  • 1
    Haven't noticed it has been closed. Basically, this is not off-topic, as on other linux distributions this stuff works as expected. It is only RPi problem. Apr 22, 2015 at 8:07


Browse other questions tagged or ask your own question.