Reputation: 1287
When I try to use NGINX and Puma I get the following error:
[error] 13416#13416: *3 connect() to unix:///home/deploy/app/tmp/pids/puma.sock failed (111: Connection refused) while connecting to upstream, client: ip.address.redacted, server: myapp.com, request: "GET / HTTP/1.1", upstream: "http://unix:///home/deploy/app/tmp/pids/puma.sock:/", host: "ip.address.redacted"
Here's just a quick breakdown of what I've done to set up this server:
When I run sudo service puma status
I get the following
● puma.service - Puma HTTP Server
Loaded: loaded (/etc/systemd/system/puma.service; disabled; vendor preset: enabled)
Active: activating (start) since Thu 2022-01-27 23:59:45 UTC; 28s ago
Main PID: 1365 (bundle)
Tasks: 12 (limit: 2274)
Memory: 155.1M
CGroup: /system.slice/puma.service
└─1365 puma 4.3.10 (tcp://0.0.0.0:3000,unix:///home/deploy/app/tmp/pids/puma.sock) [app]
Jan 27 23:59:45 localhost systemd[1]: Starting Puma HTTP Server...
Jan 27 23:59:48 localhost rbenv[1365]: Puma starting in single mode...
Jan 27 23:59:48 localhost rbenv[1365]: * Version 4.3.10 (ruby 3.1.0-p0), codename: Mysterious Traveller
Jan 27 23:59:48 localhost rbenv[1365]: * Min threads: 5, max threads: 5
Jan 27 23:59:48 localhost rbenv[1365]: * Environment: production
Jan 27 23:59:51 localhost rbenv[1365]: * Listening on tcp://0.0.0.0:3000
Jan 27 23:59:51 localhost rbenv[1365]: * Listening on unix:///home/deploy/app/tmp/pids/puma.sock
Jan 27 23:59:51 localhost rbenv[1365]: Use Ctrl-C to stop
ls -l /home/deploy/app/tmp/pids/puma.sock
produces: srwxrwxrwx 1 deploy users 0 Jan 28 00:05 /home/deploy/app/tmp/pids/puma.sock
Here's the Nginx config file found at: /etc/nginx/sites-enabled/default
upstream myapp {
server unix:///home/deploy/app/tmp/pids/puma.sock;
}
server {
listen 80;
# server_name myapp.com;
# ~2 seconds is often enough for most folks to parse HTML/CSS and
# retrieve needed images/icons/frames, connections are cheap in
# nginx so increasing this is generally safe...
keepalive_timeout 5;
# path for static files
root /home/deploy/app/public;
access_log /home/deploy/app/log/nginx.access.log;
error_log /home/deploy/app/log/nginx.error.log info;
# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/maintenance.html) {
rewrite ^(.*)$ /maintenance.html last;
break;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
# If the file exists as a static file serve it directly without
# running all the other rewrite tests on it
if (-f $request_filename) {
break;
}
# check for index.html for directory index
# if it's there on the filesystem then rewrite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
# this is the meat of the rack page caching config
# it adds .html to the end of the url and then checks
# the filesystem for that file. If it exists, then we
# rewrite the url to have explicit .html on the end
# and then send it on its way to the next config rule.
# if there is no file on the fs then it sets all the
# necessary headers and proxies to our upstream pumas
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://myapp;
break;
}
}
# Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
# BUT there's a chance it could break the ajax calls.
location ~* \.(ico|css|gif|jpe?g|png|js)(\?[0-9]+)?$ {
expires max;
break;
}
# Error pages
# error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/deploy/app/public;
}
I've added a user directive to nginx.conf thinking this would attempt to run the NGINX connection as the deploy user. However, this doesn't have any effect. Here's the first few lines of my Nginx.conf file
user deploy;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
At this point I'm not sure what to do. I don't have any experience with Puma so Im not sure if I'm doing something wrong with the config. As far as I know the puma.sock file is auto generated, Im not sure how to change the permissions/owner of the sock file or if thats even the right thing to do.
Has anyone encountered this before? What mistake am I making here?
Upvotes: 2
Views: 3417
Reputation: 56
I think you have too many / in the upstream configuration entry. It's trying to connect as if it was an HTTP url.
Try changing:
upstream myapp {
server unix:///home/deploy/app/tmp/pids/puma.sock;
}
to
upstream myapp {
server unix:/home/deploy/app/tmp/pids/puma.sock;
}
Source: nginx ngx_http_upstream_module documentation
Upvotes: 4