【问题标题】:502 Bad Gateway on platform.sh with rails 6 app + unicorn带有rails 6应用程序+独角兽的platform.sh上的502 Bad Gateway
【发布时间】:2021-05-14 06:40:04
【问题描述】:

我已经在 platform.sh 上部署了我的 rails 6 应用程序 部署成功,但是我的主页出现502错误。

502 Bad Gateway

我认为迁移或数据库创建失败。 我联系了支持人员,目前答案没有任何改变。

.aplatform.app.yaml的完整配置

    # The name of this app. Must be unique within a project.
name: app

type: 'ruby:2.7'


relationships:
    postgresdatabase: 'dbpostgres:postgresql'

# The size of the persistent disk of the application (in MB).
disk: 1024


hooks:
    build: |
      gem install bundler:2.2.8
      bundle install --without development test
    deploy: |
      RACK_ENV=production bundle exec rake db:migrate

mounts:
  'web/uploads':
    source: local
    source_path: uploads
  'tmp':
    source: local
    source_path: tmp

web:
  upstream: 
    socket_family: "unix"
  commands: 
    start: "unicorn -l $SOCKET -E production config.ru"
  locations: 
    '/': 
      root: "public"
      passthru: true
      expires: "1h"
      allow: true

config/database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>


###### PRODUCTION ############
   production:
     url: <%= ENV['DATABASE_URL'] %>
#
production:
  <<: *default
  database: LNCLASSAPPS_production
  username: LNCLASSAPPS
  password: <%= ENV['LNCLASSAPPS_DATABASE_PASSWORD'] %>

我用

设置了这个 ENV:LNCLASSAPPS_DATABASE_PASSWORD
 platform variable:create

截图

ENV variables set up

我认为是部分导致了问题。(log extrait)

 Redeploying environment master
      Preparing deployment
      Closing services router and app
      Opening application app and its relationships
      Executing deploy hook for application app
        W: `/app` is not writable.
        W: Bundler will use `/tmp/bundler20210210-161-unk7cf161' as your home directory temporarily.
        W: Rails Error: Unable to access log file. Please ensure that /app/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /app/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
        W: rake aborted!
        W: PG::ConnectionBad: could not connect to server: No such file or directory
 

现在是完整的部署日志

 Found 1 new commit
 
 Building application 'app' (runtime type: ruby:2.7, tree: a57066f)
   Generating runtime configuration.
   
   Executing build hook...
     Successfully installed bundler-2.2.8
     Parsing documentation for bundler-2.2.8
     I
   .......... GEMS INSTALLING

    
  
 
 Redeploying environment master
  Preparing deployment
  Closing services router and app
  Opening application app and its relationships
  Executing deploy hook for application app
    W: `/app` is not writable.
    W: Bundler will use `/tmp/bundler20210210-161-unk7cf161' as your home directory temporarily.
    W: Rails Error: Unable to access log file. Please ensure that /app/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /app/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
    W: rake aborted!
    W: PG::ConnectionBad: could not connect to server: No such file or directory
    W:      Is the server running locally and accepting
    W:      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
    W: /app/.global/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
    W: /app/.global/gems/pg-1.2.3/lib/pg.rb:58:in `new'
    W: /app/.global/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_handling.rb:189:in `connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:84:in `each'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
    W: /app/.global/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli/exec.rb:63:in `load'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli/exec.rb:63:in `kernel_load'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli/exec.rb:28:in `run'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli.rb:494:in `exec'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli.rb:30:in `dispatch'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli.rb:24:in `start'
    W: /app/.global/gems/bundler-2.2.8/exe/bundle:49:in `block in <top (required)>'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/friendly_errors.rb:130:in `with_friendly_errors'
    W: /app/.global/gems/bundler-2.2.8/exe/bundle:37:in `<top (required)>'
    W: /app/.global/bin/bundle:23:in `load'
    W: /app/.global/bin/bundle:23:in `<main>'
    W: Tasks: TOP => db:migrate
    W: (See full trace by running task with --trace)

 

我认为问题出在重新部署环境主部分。

【问题讨论】:

    标签: ruby-on-rails build unicorn hosted platform.sh


    【解决方案1】:

    我不知道您是否已设法解决您的问题,但似乎这是一个安装问题:

    W: `/app` is not writable.
    W: Bundler will use `/tmp/bundler20210210-161-unk7cf161' as your home directory temporarily.
    W: Rails Error: Unable to access log file. Please ensure that /app/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /app/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
    W: rake aborted!
    

    我建议将此值添加到您的 mounts 文件中的 mounts 属性中:

    mounts:
        'web/uploads':
            source: local
            source_path: uploads
        'tmp':
            source: local
            source_path: tmp
        # The new lines
        logs:
            source: local
            source_path: logs
    

    请参阅 Platform.sh official documentation 了解 Ruby。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-22
      • 2020-12-14
      • 2016-04-09
      • 2014-05-22
      • 2021-07-01
      • 2016-02-27
      • 2014-08-04
      • 2013-06-16
      相关资源
      最近更新 更多