简体   繁体   中英

Nginx cannot find unix socket file with Unicorn

I already checked the app, and everything seams to be fine (code and app config wise), also the server, database are ok, in the logs I got to this error, I already looked at this Nginx cannot find unix socket file with Unicorn (no such file or directory) but I truly don't even know where to start in order to achieve "Simply modify the listen variable in your Unicorn config file. Ex: listen "/var/sockets/unicorn.[app name].sock", then configure Nginx to proxy all connections to your server to that socket file such as server unix:/var/sockets/unicorn.[app name].sock fail_timeout=0;" if someone could please point me at some directions on how to do this it would be great.

I changed the files, but stuck in the same error, my config files are (I have deleted parts of the files for confidentiality reasons):

root = ""
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"

listen "/var/sockets/unicorn.camicase.sock"
worker_processes 2
timeout 30

and the nginx config

upstream unicorn {
  server unix:/var/sockets/unicorn.camicase.sock fail_timeout=0;
}

server {
   listen         80;
   server_name    _;
   rewrite        ^ https://$host$request_uri? permanent;
}

server {
  listen 443;
  server_name 
  root 

  ssl on;
  ssl_certificate         
  ssl_certificate_key     

  ssl_session_timeout  5m;

  ssl_protocols  SSLv2 SSLv3 TLSv1;
  ssl_ciphers HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers  on;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

So finally got the system up and running, and for all the people facing similar problems, and without munch knowledge of unicorn or nginxhere are the steps:

First make sure both services are running (unicorn is the app server and nginx is the http server), both services should be configured in /etc/init.d/.

Stop both services.

Check your policies in selinux, here is a good question on how to do it for the same error in PHP nginx error connect to php5-fpm.sock failed (13: Permission denied) , the idea is to be sure selinux isn't interfering with the read process of the socket (the socket is created by unicorn and read by nginx)

then you have to edit your config files unicorn.rb and nginx.conf, both should point to a folder different to tmp for the socket here is why https://serverfault.com/questions/463993/nginx-unix-domain-socket-error/464025#464025

So finally my configurations looks like this:

Part of nginx config file

upstream unicorn {
  server unix:/home/myuser/apps/myapp/shared/socket/unicorn.camicase.sock fail_timeout=0;
}

part of unicorn config file

listen "/home/deployer/apps/stickystreet/shared/socket/unicorn.camicase.sock"

then start unicorn and nginx, if you get a (13: Permission denied) while connecting to upstream error just do a sudo chmod 775 socket/ changing the socket for whatever folder you put your unicorn socket to be stored, then restart the nginx service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM