尝试部署时,出现“很抱歉,出现了问题”屏幕。以前它工作正常,但是当我尝试对其进行更新时,遇到了这个问题。这是我第一次部署任何东西,但我仍然不确定自己在做什么,因此我非常感谢我对我做错的事情的一些投入。
我从 unicorn.log
中收到以下错误I, [2018-10-01T19:54:53.470419 #4905] INFO -- : unlinking existing
socket=/home/deploy/production/appName/tmp/sockets
/bcrypt_unicorn.todo.sock
I, [2018-10-01T19:54:53.470635 #4905] INFO -- : listening on addr=/home/deploy/production/appName/tmp/sockets/bcrypt_unicorn.todo.sock fd=10
I, [2018-10-01T19:54:53.470737 #4905] INFO -- : worker=0 spawning...
I, [2018-10-01T19:54:53.471045 #4905] INFO -- : worker=1 spawning...
I, [2018-10-01T19:54:53.471397 #4905] INFO -- : master process ready
I, [2018-10-01T19:54:53.476589 #4908] INFO -- : worker=0 spawned pid=4908
I, [2018-10-01T19:54:53.476714 #4908] INFO -- : Refreshing Gem list
I, [2018-10-01T19:54:53.477787 #4910] INFO -- : worker=1 spawned pid=4910
I, [2018-10-01T19:54:53.477910 #4910] INFO -- : Refreshing Gem list
I, [2018-10-01T19:54:59.740522 #4908] INFO -- : worker=0 ready
I, [2018-10-01T19:54:59.744825 #4910] INFO -- : worker=1 ready
以及 /var/log/nginx/error.log 中的以下错误:
2018/10/01 20:00:41 [crit] 5067#5067: *2 connect() to unix:/home/deploy
/production/appName/tmp/sockets/bcrypto_unicorn.todo.sock failed
(2: No such file or directory) while connecting to upstream, client:
77.75.77.32, server: , request: "GET /genres/gaming HTTP/1.1", upstream:
"http://unix:/home/deploy/production/appName/tmp/sockets
/bcrypto_unicorn.todo.sock:/genres/gaming", host: "appName.com"
我用
重新启动了Nginxsudo service nginx restart
重新加载更新的配置
sudo nginx -s reload
然后停止了正在运行的Unicorn进程
ps aux | grep "unicorn master"
kill -9 PID
然后提取更新的代码以进行部署
git status
git stash save -u quick-fix
git pull origin master
git stash apply
然后迁移数据库
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake assets:precompile
然后终于重新启动了Unicorn
bundle exec unicorn -E production -c config/unicorn.rb -D
我的 unicorn.rb 文件如下:
app_path = "/home/deploy/production/appName"
working_directory app_path
pid app_path + "/tmp/pids/unicorn.pid"
stderr_path app_path + "/log/unicorn.log"
stdout_path app_path + "/log/production.log"
listen app_path + '/tmp/sockets/bcrypt_unicorn.todo.sock'
worker_processes 2
timeout 65
appName / config / nginx.conf
upstream unicorn {
server unix:/tmp/sockets/bcrypto_unicorn.todo.sock fail_timeout=0;
}
server{
listen 80 default deferred;
root /home/deploy/production/appName/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;
}
error_page 403 404 /404.html;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
和 /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml applicati$
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/ etc / nginx / sites-enabled / bcrypto
upstream bcrypto_unicorn {
server unix:/home/deploy/production/appName/tmp/sockets/bcrypto_unicorn.todo.sock fa$
}
server {
listen 80 default deferred;
root /home/deploy/production/appName/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @bcrypto_unicorn;
location @bcrypto_unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://bcrypto_unicorn;
}
error_page 422 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 60;
}
有人可以指出我在这里做错的方向吗?
答案 0 :(得分:1)
问题在于Nginx在Unicorn设置插座的地方寻找插座。
Nginx尝试在以下位置找到套接字:
/home/deploy/production/appName/tmp/sockets/byc2-master_unicorn.todo.sock
,而Unicorn配置将其设置为/tmp/appName_unicorn.todo.sock
要解决此问题,两个路径必须相同。因此,您需要在 / etc / nginx / sites-enabled / bcrypto 的 upstream 指令中放置相同的路径,并在 listen 中定义该路径> unicorn.rb
中的指令然后重新启动Unicorn并重新加载Nginx
答案 1 :(得分:1)
首先,检查您的tmp/sockets
文件夹是否存在。如果没有,请使用以下命令创建文件夹
mkdir /home/deploy/production/appName/tmp/sockets
然后,通过修改socket
unicorn.rb
更改为与nginx相同的路径。
listen app_path + '/tmp/sockets/bcrypt_unicorn.todo.sock'
最后,重新启动独角兽
bundle exec unicorn -E production -c config/unicorn.rb -D