我有一个 ruby on rails 项目,它使用 Nginx、Puma 和 Capistrano 托管在 Digital Ocean droplet 上。 我正在接管这个项目,但没有这个项目的跟踪回购。所以我拥有的唯一源代码在远程服务器上。 我必须通过 D.O UI 重新启动 Droplet 服务器才能访问控制台。重新启动后,某些页面未加载(而某些页面加载)。此时,对代码库进行了 zero 更改。 查看
production.log
,它针对未加载的页面吐出一个常见的一般错误:
TypeError (no implicit conversion of nil into String):
...
Completed 500 Internal Server Error in 11ms (Views: 10.0ms | Allocations: 3709)
所以我挖得更深。这就是我得到的
/var/log/nginx/error.log
:
2023/05/03 18:59:02 [crit] 16157#16157: *1 connect() to unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock failed (2: No such file or directory) while connecting to upstream, client: 100.11.109.141, server: ms.explore.myapp.com, request: "GET /users/sign_up HTTP/2.0", upstream: "http://unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock:/users/sign_up", host: "ms.explore.myapp.com", referrer: "https://ms.explore.myapp.com/users/sign_up"
2023/05/03 18:59:03 [crit] 16157#16157: *1 connect() to unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock failed (2: No such file or directory) while connecting to upstream, client: 100.11.109.141, server: ms.explore.myapp.com, request: "GET /users/sign_up HTTP/2.0", upstream: "http://unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock:/users/sign_up", host: "ms.explore.myapp.com", referrer: "https://ms.explore.myapp.com/users/sign_up"
2023/05/03 18:59:03 [crit] 16157#16157: *1 connect() to unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock failed (2: No such file or directory) while connecting to upstream, client: 100.11.109.141, server: ms.explore.myapp.com, request: "GET /users/sign_up HTTP/2.0", upstream: "http://unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock:/users/sign_up", host: "ms.explore.myapp.com", referrer: "https://ms.explore.myapp.com/users/sign_up"
我检查过
/var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock
存在。
这是 /etc/nginx/sites-available/myapp:
upstream puma {
server unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock;
}
server {
listen 80;
server_name ms.explore.myapp.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/ms.explore.myapp.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ms.explore.myapp.com/privkey.pem;
server_name ms.explore.myapp.com;
root /var/www/vhosts/myapp/current/public;
add_header X-Frame-Options "DENY";
location ^~ /(assets|packs)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location = /robots.txt {
add_header Content-Type text/plain;
return 200 "User-agent: *\nAllow: /\n";
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_pass http://puma;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
client_max_body_size 25M;
rewrite ^/contacts/new$ /contact-us permanent;
rewrite ^/program/resources/course-navigation$ /program/course-navigation permanent;
}
运行
ps aux | grep puma
显示puma连接到正确的sock文件:
deploy 16523 0.0 5.8 410660 120276 ? S 18:59 0:00 puma 3.12.1 (unix:///var/www/vhosts/myapp/shared/tmp/sockets/myapp-puma.sock)
deploy 16525 0.0 6.3 1161592 130524 ? Sl 18:59 0:00 puma: cluster worker 0: 16523
deploy 16536 0.0 6.4 1161592 131408 ? Sl 18:59 0:00 puma: cluster worker 1: 16523
deploy 19690 0.0 0.0 14860 1072 pts/1 S+ 19:16 0:00 grep --color=auto puma
这里会发生什么?我不太熟悉 Capistrano 和它的全部功能。我怀疑重启服务器会忽略 Capistrano 的自动设置步骤,这可能是配置 puma 服务工作者和 nginx 服务器错误。
我已经尝试分别用
sudo service puma restart
和sudo service nginx restart
重启puma和nginx。以及尝试加载 D.O. 提供的备份。但似乎没有帮助。
我无法执行部署过程,因为我在本地没有源代码。 非常感谢一些服务器/ruby/rails 专家的帮助!提前谢谢你!
编辑 以下是更多相关信息:
config/deploy.rb
:
# config valid for current version and patch releases of Capistrano
lock "~> 3.17.0"
set :application, "myapp"
set :repo_url, "[email protected]:cra/myapp.git"
set :deploy_to, "/var/www/vhosts/myapp"
append :linked_files, "config/database.yml", "config/master.key", "config/features.yml"
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system", "public/uploads", "vendor/bundle"
set :keep_releases, 3
set :keep_assets, 2
这里还有
config/deploy/ms-instance.rb
:
server "myapp-ms", user: "deploy", roles: %w(app db web)
set :puma_threads, [4, 16]
set :puma_workers, 2
set :pty, true
set :use_sudo, false
set :stage, :production
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord