###前提・実現したいこと
Ruby on Rails5で作ったアプリをEC2デプロイ。
Capistranoを使用し、Nginxとunicornを使用。
参考にしたサイト: http://qiita.com/naoki_mochizuki/items/657aca7531b8948d267b
###発生している問題・エラーメッセージ
アプリのルートファイルが表示されないです。
bundle exec cap production deploy
を実行し、デプロイは完了しました。
Nginxを起動し、サイトを表示させようとしたのですが、
「Welcome to nginx on the Amazon Linux AMI!」
の画面になってしまいました。
その後、/etc/nginx/nginx.conf
のrootを以下のように /var/www/introduction/current/public
と編集したのですが、「403 Forbidden」と表示されてしまいました。
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; index index.html index.htm; server { listen 80 default_server; listen [::]:80 default_server; server_name localhost; root /var/www/introduction/current/public; include /etc/nginx/default.d/*.conf; location / { } include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
エラーメッセージは
`2017/03/18 09:41:08 [error] 6367#0: *92 directory index of "/var/www/introduction/current/public/" is forbidden, client: 60.135.210.91, server: localhost, request: "GET / HTTP/1.1", host: "www.(省略)"`
となっております。
パーミッションは、/var/www/introduction/current/public
で
var 755
www 755
introduction 755
current 777
でした。
###その他の設定ファイル
/etc/nginx/conf.d/introduction.conf
は以下のように設定してあります。
error_log /var/www/introduction/current/log/nginx.error.log; access_log /var/www/introduction/current/log/nginx.access.log; client_max_body_size 2G; upstream app_server { server unix:/var/www/introduction/current/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name 127.0.0.1; keepalive_timeout 5; root /var/www/introduction/current/public; try_files $uri/index.html $uri.html $uri @app; location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/introduction/current/public; } }
またunicornnの方は、/var/www/introduction/current/config/unicorn
にて、以下のように設定されています。
$worker = 2 $timeout = 30 $app_dir = "/var/www/introduction/current" $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid preload_app true before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin Process.kill "QUIT", File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
###追記 /etc/nginx/conf.d/introduction.confの設定を修正した結果
「このページは動作していません
www.ateam17-introduce.xyz では現在このリクエストを処理できません。
HTTP ERROR 500」
と表示されました。
unicorn.logには以下のように表示されました。
E, [2017-03-21T17:50:24.305630 #20611] ERROR -- : app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError) E, [2017-03-21T17:50:24.305755 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:513:in `validate_secret_key_config!' E, [2017-03-21T17:50:24.305791 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:246:in `env_config' E, [2017-03-21T17:50:24.305816 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:693:in `build_request' E, [2017-03-21T17:50:24.305840 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:521:in `build_request' E, [2017-03-21T17:50:24.305862 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:521:in `call' E, [2017-03-21T17:50:24.305884 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:562:in `process_client' E, [2017-03-21T17:50:24.305905 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:658:in `worker_loop' E, [2017-03-21T17:50:24.305922 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers' E, [2017-03-21T17:50:24.305943 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:132:in `start' E, [2017-03-21T17:50:24.305957 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/gems/unicorn-5.2.0/bin/unicorn:126:in `<top (required)>' E, [2017-03-21T17:50:24.305975 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/bin/unicorn:23:in `load' E, [2017-03-21T17:50:24.306012 #20611] ERROR -- : /var/www/introduction/shared/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
###追記2 secret_key_base のエラーに関して
アプリのconfig/deploy.rbにて、
〜 set :linked_files, fetch(:linked_files, []).push('config/settings.yml') 〜
と書いた後、/var/www/introduction/shared/config/settings.yml
に
production: secret_key_base: ~~~
を記入し、デプロイをしましたが、
Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)
が発生したままです。
###追記2に関して試したこと
・デプロイ後のsecrets.ymlに直接記入
・export SECRET_KEY_BASE=〜〜〜
・~/.bashrc
と~/.bash_profile
の中にexport SECRET_KEY_BASE=〜〜〜
を記入
echo $SECRET_KEY_BASE
を実行するとターミナル上では表示されるのですが、unicornをリスタートさせても同じエラーのままでした。
回答1件
あなたの回答
tips
プレビュー