【发布时间】:2020-06-16 13:03:50
【问题描述】:
我是第一次在 upcloud 上设置 VPS。我正在使用带有 Nginx 的独角兽 5.5.5。 Rails 4.2.8 和 ruby 2.4.2。我的 Nginx 服务运行良好。不显示任何错误。每当我启动独角兽服务时,我都会收到此错误。我按照本教程进行操作。
https://medium.com/@manishyadavv/how-to-deploy-ruby-on-rails-apps-on-aws-ec2-7ce55bb955fa
F, [2020-06-16T12:44:20.611895 #12683] FATAL -- : error adding listener addr=/tmp/unicorn.sock
/usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/socket_helper.rb:132:in `bind_listen': socket=/tmp/unicorn.sock specified but it is not a socket! (ArgumentError)
from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:243:in `listen'
from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:851:in `block in bind_new_listeners!'
from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:851:in `each'
from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:851:in `bind_new_listeners!'
from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:142:in `start'
from /usr/share/rvm/gems/ruby-2.4.2/gems/unicorn-5.5.5/bin/unicorn:128:in `<top (required)>'
from /usr/share/rvm/gems/ruby-2.4.2/bin/unicorn:23:in `load'
from /usr/share/rvm/gems/ruby-2.4.2/bin/unicorn:23:in `<main>'
from /usr/share/rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:24:in `eval'
from /usr/share/rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:24:in `<main>'
我的 unicorn.sock 文件是空的,如果这是一个新手错误,我很抱歉,但我已经被这个问题困扰了 2 天。请帮帮我。 这是我在 etc/init.d 目录中的 unicorn_repo 文件
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn app server
# Description: starts unicorn using start-stop-daemon
### END INIT INFO
set -e
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
# app settings
USER="root"
APP_NAME="soup"
APP_ROOT="/$USER/$APP_NAME"
ENV="production"
# environment settings
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.pid"
OLD_PID="$PID.oldbin"
这是我的 nginx/默认文件
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 0.0.0.0;
server_name localhost;
root root/soup/;
try_files $uri/index.html $uri @app;
location @app {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
这是我的 unicorn.rb 文件。
# set path to application
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir
# Set unicorn options
worker_processes 2
preload_app true
timeout 30
# Set up socket location
listen "/tmp/unicorn.sock", :backlog => 64
listen 3000, :tcp_nopush => true
# Logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
# Set master PID location
pid "#{shared_dir}/pids/unicorn.pid"
~
~
~
~
【问题讨论】:
-
我不是 100% 确定,但我不喜欢一件事:在你的独角兽初始化文件中,你使用的是
USER=root。首先,一个好的建议是始终使用不同于 root 的用户。此外,EC2 实例的默认用户通常是ubuntu。尝试改变它。如果不起作用,请尝试将套接字路径从/tmp/unicorn.sock移动到另一个路径,例如/home/ubuntu/unicorn.sock。如果没有任何效果,请将您的config/unicorn.rb文件也添加到问题中。 -
我已经添加了 unicorn.rb 。先生,为什么它说“它不是套接字,我觉得 unicorn.sock 中应该有一些代码但它是空的”。你怎么看?
标签: ruby-on-rails ruby nginx unicorn