Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Unicorn/Nginx部署-未创建Unicorn.sock(导致502错误)_Ruby On Rails_Sockets_Nginx_Unicorn - Fatal编程技术网

Ruby on rails Unicorn/Nginx部署-未创建Unicorn.sock(导致502错误)

Ruby on rails Unicorn/Nginx部署-未创建Unicorn.sock(导致502错误),ruby-on-rails,sockets,nginx,unicorn,Ruby On Rails,Sockets,Nginx,Unicorn,我的主要问题是,在尝试访问我的应用程序时,我收到了502网关错误(标准的“出错了”-rails错误,但控制台说是502) 检查nginx错误日志会显示以下内容: 2015/05/10 20:06:09 [crit] 32270#0: *10 connect() to unix:/var/sockets/unicorn.depot.sock failed (2: No such file or directory) while connecting to upstream /home/deplo

我的主要问题是,在尝试访问我的应用程序时,我收到了502网关错误(标准的“出错了”-rails错误,但控制台说是502)

检查nginx错误日志会显示以下内容:

2015/05/10 20:06:09 [crit] 32270#0: *10 connect() to unix:/var/sockets/unicorn.depot.sock failed (2: No such file or directory) while connecting to upstream
/home/deployer/apps/depot/current# bundle exec unicorn --restart
bundler: command not found: unicorn
实际上,/var/sockets中没有文件

最初,我将套接字路径设置为/tmp,但读取后,/tmp文件夹中的文件只能由创建它们的服务访问,我将它们移动到/var文件夹中

但是还有更多的问题——pid文件也没有创建

在继续我的配置文件之前-我有一种奇怪的感觉,我的unicorn_init.sh中的这一行可能会导致问题:

CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
因为当我手动执行时,我会收到以下信息:

2015/05/10 20:06:09 [crit] 32270#0: *10 connect() to unix:/var/sockets/unicorn.depot.sock failed (2: No such file or directory) while connecting to upstream
/home/deployer/apps/depot/current# bundle exec unicorn --restart
bundler: command not found: unicorn
但是,我害怕通过捆绑安装在vps上安装unicorn(unicorn当然包括在我的Gemfile中),正如shell告诉我的:

/home/deployer/apps/depot/current# bundle install  
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and 
installing your bundle as root will break this 
application for all non-root users on this machine.
我将感谢任何反馈,提前感谢

以下是我的配置文件:

独角兽

worker_processes 2
working_directory "/home/deployer/apps/depot/current"

# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true

timeout 30

# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/var/sockets/unicorn.depot.sock", :backlog => 64

pid "/home/deployer/apps/depot/current/tmp/pids/unicorn.pid"

# Set the path of the log files inside the log folder of the testapp
stderr_path "/home/deployer/apps/depot/current/log/unicorn.stderr.log"
stdout_path "/home/deployer/apps/depot/current/log/unicorn.stdout.log"

before_fork do |server, worker|
# This option works in together with preload_app true setting
# What is does is prevent the master process from holding
# the database connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
# Here we are establishing the connection after forking worker
# processes
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end
nginx.conf

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

server {
    listen 80 default deferred;
    # server_name example.com
    root /home/deployer/apps/depot/current/public;

    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 Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn-depot;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}
麒麟_init.sh

#!/bin/sh
### BEGIN INIT INFO
# Provides:          unicorn
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Manage unicorn server
# Description:       Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e

# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/depot/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=deployer
set -u

OLD_PIN="$PID.oldbin"

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}

run () {
  if [ "$(id -un)" = "$AS_USER" ]; then
    eval $1
  else
    su -c "$1" - $AS_USER
  fi
}

case "$1" in
start)
  sig 0 && echo >&2 "Already running" && exit 0
  run "$CMD"
  ;;
stop)
  sig QUIT && exit 0
  echo >&2 "Not running"
  ;;
force-stop)
  sig TERM && exit 0
  echo >&2 "Not running"
  ;;
restart|reload)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  run "$CMD"
  ;;
upgrade)
  if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
  then
    n=$TIMEOUT
    while test -s $OLD_PIN && test $n -ge 0
    do
      printf '.' && sleep 1 && n=$(( $n - 1 ))
    done
    echo

    if test $n -lt 0 && test -s $OLD_PIN
    then
      echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
      exit 1
    fi
    exit 0
  fi
  echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  run "$CMD"
  ;;
reopen-logs)
  sig USR1
  ;;
*)
  echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  exit 1
  ;;
esac
#/垃圾箱/垃圾箱
###开始初始化信息
#提供:独角兽
#必需的开始:$remote_fs$syslog
#所需停止:$remote_fs$syslog
#默认开始:2 3 4 5
#默认停止:0 1 6
#简短描述:管理unicorn服务器
#描述:启动、停止、重新启动特定应用程序的unicorn服务器。
###结束初始化信息
set-e
#请随意更改应用程序的以下任何变量:
超时=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/depot/current
PID=$APP_ROOT/tmp/pids/unicorn.PID
CMD=“cd$APP\u ROOT;bundle exec unicorn-D-c$APP\u ROOT/config/unicorn.rb-E production”
AS_USER=deployer
set-u
OLD_PIN=“$PID.oldbin”
sig(){
测试-s“$PID”和压井-1`cat$PID`
}
oldsig(){
测试-s$OLD_PIN和kill-$1`cat$OLD_PIN`
}
运行(){
如果[“$(id-un)”=“$作为用户”];则
估价1美元
其他的
su-c“$1”-$AS_用户
fi
}
案件“$1”
开始)
信号0&&echo>&2“已在运行”&退出0
运行“$CMD”
;;
(停止)
sig退出&退出0
echo>&2“未运行”
;;
(强制停止)
sig术语&退出0(&F)
echo>&2“未运行”
;;
重新启动(重新加载)
sig HUP和echo已重新加载确定和退出0(&E)
echo>&2“无法重新加载,改为启动“$CMD”
运行“$CMD”
;;
(升级)
如果sig USR2&&sleep 2&&sig 0&&oldsig退出
然后
n=$TIMEOUT
而测试-s$OLD_PIN和测试$n-ge 0
做
printf'.&&sleep 1&&n=$($n-1))
完成
回声
如果测试$n-lt 0和测试-s$OLD\u PIN
然后
echo>&2“$OLD_PIN在$TIMEOUT秒后仍然存在”
出口1
fi
出口0
fi
echo>&2“无法升级,改为启动“$CMD”
运行“$CMD”
;;
重新打开日志)
sig USR1
;;
*)
echo>&2“用法:$0”
出口1
;;
以撒

我也有这个问题!你的问题解决了吗?怎么做?@ryan2johnson 9不幸的是-没有。我完全改用彪马而不是独角兽,使用了这本很棒的教程:像一个魔咒一样工作!好的-这对你没有帮助,但也许有一天会有其他人:我在部署后手动重启我的独角兽应用程序,摆脱了麻烦。Capistrano部署使用run
task:restart do invoke'unicorn:legacy_restart'end
,但这似乎没有将套接字放在正确的位置,但是从in-server手动重新启动bundle exec unicorn-D-c/home/deploy/apps/my_-app/current/config/unicorn/staging.rb-E staging