我在尝试使用 capistrano/nginx 和乘客部署我的 Rails 应用程序时遇到错误,capistrano 工作正常,我可以很好地运行我的部署命令,但是由于来自乘客 gem 的错误,我无法访问我的端点。
这是在乘客尝试访问我的域时创建的临时 html 文件中记录的错误。
`错误响应 错误代码:404
消息:找不到文件。
错误代码解释:HTTPStatus.NOT_FOUND - 没有任何内容与给定的 URI 匹配。`
这就是您查看页面时显示的内容。
We're sorry, but something went wrong. The issue has been logged for investigation. Please try again later.
这是 nginx 错误日志显示的内容
App 79721 output: from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/bundler-2.4.22/lib/bundler.rb:208:in `definition'
App 79721 output: from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/bundler-2.4.22/lib/bundler.rb:156:in `setup'
App 79721 output: from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
App 79721 output: from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
App 79721 output: from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
[ E 2024-06-30 12:40:49.9999 77711/T2g age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /home/deploy/myappname/current: The application process exited prematurely.
Error ID: bbc2b04f
Error details saved to: /tmp/passenger-error-v7N1qC.html
[ E 2024-06-30 12:40:50.0044 77711/T6 age/Cor/Con/CheckoutSession.cpp:281 ]: [Client 1-16] Cannot checkout session because a spawning error occurred. The identifier of the error is bbc2b04f. Please see earlier logs for details about the error.
这就是我的 gemfile 的样子(这是一个旧的 ruby 应用程序,我计划在部署设置后升级)
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.7', '>= 5.0.7.2'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'
gem 'jwt'
gem 'capistrano', '~> 3.11'
gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'pry-byebug'
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
这就是我的 nginx 配置的样子
server {
listen 80;
listen [::]:80;
server_name mydomain.app;
root /home/deploy/myappname/current/public;
passenger_enabled on;
passenger_app_env production;
passenger_preload_bundler on;
location /cable {
passenger_app_group_name mydomain_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
# Return 404 for requests to any unknown routes
error_page 404 /404.html;
location = /404.html {
internal;
}
# Additional error handling
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
我正在按照本教程进行操作,其他项目也遵循该教程,在同一托管 DigitalOcean VPS ubuntu 22.04 LTS 上运行时没有出现这些问题
https://gorails.com/deploy/ubuntu/22.04
搜索客运项目github 堆栈溢出搜索 谷歌搜索 ChatGPT 故障排除
本来打算向乘客开一张问题票,但上面说要先尝试 stackoverflow。
如果您遇到此问题,似乎无法找到该乘客具体抱怨的文件。最终对我有用的是将 ruby 版本从 2.6.1 升级到 2.7.1 ,重新安装捆绑器以及所有 gem。然后使用
重新部署应用程序cap production deploy
我希望有一个更好的解决方案,但 2.6.1 已经相当过时了,无论如何我都计划升级,跳到 2.7.1 为我解决了这个问题,没有任何其他更改。