Connection refused errors in nginx logs when it tries to connect to hhvm

Jean-François Beauchamp asked:

My nginx web server has a lot of lines like this one in its error.log file:

2017/12/30 20:30:00 [error] 5620#5620: *21 connect() to unix:/var/run/hhvm/hhvm.sock failed 
(111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, 
server: beauchamp.me, request: "GET /test.php HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/hhvm/hhvm.sock:", host: "www.xxxxxxx.com"

and I am unable to figure out why. hhvm seems to be failing all the time, so my server reverts to using FPM to run PHP pages.

hhvm version: HipHop VM 3.23.2 (rel) 
nginx version: nginx/1.12.2 
apache2 version: version: Apache/2.4.10 (Debian)   (used for FPM fallback) 
Linux version: Debian 8 (Jessie)

And here is my PHP config for nginx:

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    proxy_intercept_errors on;
    error_page 502 = @fpm;

    # try_files $uri /index.php;
    include fastcgi_params;
    fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
}

location @fpm {
  # try_files $uri /index.php;
  include fastcgi_params;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_index index.php;
}

and the permissions on the hhvm.sock file:

root@Debian-82-jessie-64-LAMP /var/log/nginx # ls -als /var/run/hhvm/hhvm.sock
0 srwxrw---- 1 www-data www-data 0 Dec 30 18:43 /var/run/hhvm/hhvm.sock

By the way, I rather use Unix sockets than TCP sockets.

UPDATE:

Here is my hhvm server.ini file content:

; php options

pid = /var/run/hhvm/pid

; hhvm specific 

; hhvm.server.port = 9000
hhvm.server.file_socket=/var/run/hhvm/hhvm.sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/cache/hhvm/hhvm.hhbc

My answer:


You need to do two things:

  1. Configure hhvm to listen on the same socket you specified in the nginx configuration.
  2. Restart hhvm.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.