简体   繁体   English

Capistrano运行没有错误,但我的页面仍然没有显示

[英]Capistrano runs without errors but my page still doesn't show

I've set up my rails application and working on deploying it, and I've ran into an issue I have no clue how to solve. 我已经安装了Rails应用程序并正在进行部署,但是遇到了一个我不知道如何解决的问题。 I run cap production deploy and it runs without any errors. 我运行cap production deploy ,它运行时没有任何错误。

My capfile: 我的capfile:

...
require 'capistrano/deploy'
require 'capistrano/rails'

production.rb production.rb

role :app, %w{deploy@ip}
role :web, %w{deploy@ip}
role :db,  %w{deploy@ip}

deploy: 部署:

set :application, 'mainapp'
set :repo_url, 'git@github.com:almnes/mainapp.git'
set :deploy_to, '/opt/www/mainapp'
set :user, 'deploy'
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets}

namespace :deploy do

  %w[start stop restart].each do |command|
    desc 'Manage Unicorn'
    task command do
      on roles(:app), in: :sequence, wait: 1 do
        execute "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
      end      
    end
  end

  after :publishing, :restart

end

My unicorn.log in production: 我在生产中的unicorn.log:

I, [2015-12-16T09:15:39.575346 #1128]  INFO -- : master complete
I, [2015-12-16T09:15:50.979431 #1131]  INFO -- : listening on addr=/tmp/unicorn.mainapp.sock fd=10
I, [2015-12-16T09:15:50.983388 #1131]  INFO -- : worker=0 spawning...
I, [2015-12-16T09:15:50.984460 #1131]  INFO -- : master process ready
I, [2015-12-16T09:15:50.989710 #1134]  INFO -- : worker=0 spawned pid=1134
I, [2015-12-16T09:15:50.989947 #1134]  INFO -- : Refreshing Gem list
I, [2015-12-16T09:15:55.351175 #1134]  INFO -- : worker=0 ready
I, [2015-12-16T09:18:54.364835 #1131]  INFO -- : reloading config_file=/opt/www/mainapp/current/config/unicorn.rb
I, [2015-12-16T09:18:54.373599 #1131]  INFO -- : done reloading config_file=/opt/www/mainapp/current/config/unicorn.rb
I, [2015-12-16T09:18:54.527631 #1131]  INFO -- : reaped #<Process::Status: pid 1134 exit 0> worker=0
I, [2015-12-16T09:18:54.527945 #1131]  INFO -- : worker=0 spawning...
I, [2015-12-16T09:18:54.530843 #3986]  INFO -- : worker=0 spawned pid=3986
I, [2015-12-16T09:18:54.531103 #3986]  INFO -- : Refreshing Gem list
I, [2015-12-16T09:18:57.170960 #3986]  INFO -- : worker=0 ready
I, [2015-12-16T09:23:19.949319 #1131]  INFO -- : reaped #<Process::Status: pid 3986 exit 0> worker=0
I, [2015-12-16T09:23:19.949764 #1131]  INFO -- : master complete
I, [2015-12-16T09:23:30.987309 #1132]  INFO -- : listening on addr=/tmp/unicorn.mainapp.sock fd=10
I, [2015-12-16T09:23:30.987889 #1132]  INFO -- : worker=0 spawning...
I, [2015-12-16T09:23:30.988912 #1132]  INFO -- : master process ready
I, [2015-12-16T09:23:31.000132 #1135]  INFO -- : worker=0 spawned pid=1135
I, [2015-12-16T09:23:31.000368 #1135]  INFO -- : Refreshing Gem list
I, [2015-12-16T09:23:35.040186 #1135]  INFO -- : worker=0 ready

Production log just contains the migration (which was successful). 生产日志仅包含迁移(成功)。

nginx: nginx的:

upstream unicorn_mainapp {
  server unix:/tmp/unicorn.mainapp.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  server_name: ip_address;
  root /opt/www/mainapp/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 Host $http_host;  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_pass http://unicorn_mainapp;
  }

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

and my unicorn production side config: 和我的独角兽生产端配置:

#!/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=/opt/www/mainapp/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=deploy
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 "
  exit 1
  ;;
esac

and finally my apps unicorn.rb file: 最后是我的应用程序unicorn.rb文件:

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

listen "/tmp/unicorn.mainapp.sock"
worker_processes 1
timeout 30

also if it might be of use im trying to run it on the IP, not a domain. 如果试图在IP(而不是域)上运行它,也可能有用。 I have no idea what's wrong but I got a feeling it's something to do with nginx. 我不知道出了什么问题,但是我感觉这与nginx有关。

Setting up the Unicorn in nginx.conf 在nginx.conf中设置独角兽

There are 4 definitions on the Unicorn, in your example, unicorn_mainapp that need to match or the sockets will misalign and you'll get nginx socket errors. 在Unicorn上有4个定义,在您的示例中,unicorn_mainapp需要匹配,否则套接字将不对齐,并且您会收到nginx套接字错误。 I've added them to your example init file below. 我已将它们添加到下面的示例init文件中。

  upstream unicorn_mainapp {
      server unix:/tmp/unicorn.mainapp.sock fail_timeout=0;
    }

server {
  listen 80 default deferred;
  server_name: example.com
  root /opt/www/mainapp/current/public;

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

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

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

Socket file permissions can be another sticky point, but set the unicorns consistenly as above, and let me know what you see. 套接字文件权限可能是另一个棘手的问题,但是请像上面一样设置独角兽,并让我知道您看到了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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