【问题标题】:Deploying Rails App to AWS using capistrano, puma and nginx. Always show Welcome to nginx使用 capistrano、puma 和 nginx 将 Rails 应用程序部署到 AWS。总是显示 Welcome to nginx
【发布时间】:2017-08-23 02:40:48
【问题描述】:

美好的一天!我想问是否有人在使用 Capistrano、Puma 和 NGINX 部署 Rails 应用程序后遇到这个问题。欢迎使用 nginx!页面出现而不是 Rails 页面根路径?我试图解决这个问题,但没有运气。希望有人可以帮助我。谢谢你

这是我的 nginx 配置

upstream app {
  # Path to Puma SOCK file, as defined previously
  server unix:/home/deploy/appname/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
  listen 80;
  server_name localhost;
  root /home/deploy/appname/current/public;
  try_files $uri/index.html $uri @app;
  location / {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_pass http://app;
  }
  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}  

and cap deploy.rb

# config valid only for current version of Capistrano
lock "3.8.0"
set :application, 'appname'
set :branch, :aws_deployment_v1
set :repo_url, git repo link
set :deploy_to, '/home/deploy/appname'
set :pty, true
set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 5
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.1.6' # Edit this if you are using MRI Ruby
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"    #accept array for multi-bind
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false

【问题讨论】:

  • 这是第一次部署到这个堆栈吗?因为这听起来像是 NGINX 配置问题
  • 不,我在以前的 rails 应用程序上具有相同的配置,我只是重命名了应用程序名称。我以前的部署,运行良好。不知道我当前的应用会发生什么。
  • 请看我的 nginx 配置
  • upstream app { # Puma SOCK 文件的路径,如之前定义的 server unix:/home/deploy/appname/shared/tmp/sockets/puma.sock fail_timeout=0; }
  • 服务器 { 听 80; server_name 本地主机;根 /home/deploy/appname/current/public; try_files $uri/index.html $uri @app; location / { proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header 主机 $host;代理重定向关闭; proxy_http_version 1.1; proxy_set_header 连接''; proxy_pass app; }

标签: ruby-on-rails amazon-web-services nginx capistrano3 puma


【解决方案1】:

您是否尝试过切换index.html@app

try_files $uri @app $uri/index.html;

【讨论】:

    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 2018-01-30
    • 2020-04-22
    • 1970-01-01
    • 2023-04-07
    • 2014-10-07
    • 1970-01-01
    • 2022-01-07
    相关资源
    最近更新 更多