前提・実現したいこと
Qiitaの記事を参考にしてデプロイに挑戦しています。
nginxを正しく設定してrailsアプリをunicorn経由で表示したいです。
バージョン | |
---|---|
Rails | 5.0.4 |
発生中問題
SafariでElastic IP
にアクセス → ページを開けませんでした
ChromeでElastic IP
にアクセス → アクセスできません。応答時間が長すぎる
ログで気になる部分
log/unicorn.log
INFO -- : Refreshing Gem list INFO -- : unlinking existing socket=/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock ← ★ココ INFO -- : listening on addr=/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock fd=11 ← ★ココ INFO -- : master process ready INFO -- : worker=0 ready INFO -- : worker=1 ready
/var/log/nginx/error.log
*13 connect() to unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 10.0.1.64, server: 13.114.42.65, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock:/", host: "10.0.1.131" *15 connect() to unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 10.0.0.43, server: 13.114.42.65, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock:/", host: "10.0.1.131" *17 connect() to unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 10.0.1.64, server: 13.114.42.65, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock:/", host: "10.0.1.131" ...以下同じような記述
設定ファイル
/etc/nginx/conf.d/{アプリ名}.conf
upstream unicorn_server { server unix:/var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80 default; client_max_body_size 4G; server_name 13.114.42.65; keepalive_timeout 5; # Location of our static files root /var/www/projects/{アプリ名}/public; location ~ ^/assets/ { root /var/www/projects/{アプリ名}/public; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://unicorn_server; break; } } error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/projects/{アプリ名}/public; } }
var/www/projects/{アプリ名}/config/unicorn.conf.rb
# set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/projects/offisee" $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 # set config worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid # loading booster preload_app true # before starting processes 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 finishing processes after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
ご助言頂ける方、宜しくお願いします。
追記(パーミッション)
パーミッションが原因のこともあるようなので記述。
$ ls -l /var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock → srwxrwxrwx 1 {ユーザ名} {ユーザ名} 0 Aug 5 03:07 /var/www/projects/{アプリ名}/tmp/sockets/.unicorn.sock $ ls -ld /var/www/projects/{アプリ名}/tmp/sockets → drwxrwxr-x 2 {ユーザ名} {ユーザ名} 4096 Aug 5 03:07 /var/www/projects/{アプリ名}/tmp/sockets $ ls -ld /var/www/projects/{アプリ名}/tmp → drwxrwxr-x 6 {ユーザ名} {ユーザ名} 4096 Aug 5 01:06 /var/www/projects/{アプリ名}/tmp $ ls -ld /var/www/projects/{アプリ名} → drwxrwxr-x 15 {ユーザ名} {ユーザ名} 4096 Aug 5 01:05 /var/www/projects/{アプリ名} $ ls -ld /var/www/projects → drwxr-xr-x 5 {ユーザ名} root 4096 Aug 5 00:35 /var/www/projects $ ls -ld /var/www → drwxr-xr-x 3 {ユーザ名} root 4096 Aug 5 00:07 /var/www $ ls -ld /var → drwxr-xr-x 20 {ユーザ名} root 4096 Aug 4 23:56 /var
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/08/11 01:27
2017/08/17 02:11 編集