awsからさくらのクラウドにサーバー移行しています。
awsのamazonLinaxでは正常に動作していました。
$bundle exec unicorn_rails -c config/unicorn.rb -E production -D
$sudo systemctl start nginx
上記のコマンドで実行
rails のアプリケーションのページは表示されず、nginxのページに飛んでしまいます。
この問題を解決したいです。
トライしたこと
CentOS 7でNginx、Unicornにハマるに
NginxとUnicorn間で/tmpを共有できないということわかり、
CentOS7 でrailsの環境構築も同じように/tmp
とは書いてなかったので
変更してみましたがうまくいきませんでした。
環境
さくらのクラウド CentOS7
Ruby : ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Rails :4.2.3
nginx + unicorn
でrailsアプリケーションの環境を構築しています。
実行コマンド
$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D
設定ファイル
config/unicorn.rb
rails_root = File.expand_path('../../', __FILE__) worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 15 preload_app true #listen "#{rails_root}/tmp/unicorn.sock" #pid "#{rails_root}/tmp/unicorn.pid" listen "#{rails_root}/shared/tmp/unicorn.sock" pid "#{rails_root}/shared/tmp/unicorn.pid" before_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn master intercepting TERM and sending myself QUIT instead' Process.kill 'QUIT', Process.pid end defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end after_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' end defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
/etc/nginx/conf.d/local.conf
upstream unicorn { server unix:/home/ユーザー名/アプリ名/shared/tmp/unicorn.sock; } server { listen 80; server_name 127.0.0.1; access_log /var/log/nginx/ユーザー名_access.log; error_log /var/log/nginx/ユーザー名_error.log; root /home/ユーザー名/アプリ名/public; client_max_body_size 100m; error_page 404 /404.html; error_page 500 502 503 504 /500.html; try_files $uri/index.html $uri.html $uri @unicorn; location @unicorn { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://unicorn; } }
log
/var/log/nginx/error.log
2016/02/20 14:49:34 [warn] 9501#0: conflicting server name "localhost" on 0.0.0.0:80, ignored 2016/02/20 14:49:34 [warn] 9502#0: conflicting server name "localhost" on 0.0.0.0:80, ignored 2016/02/20 14:59:07 [warn] 1036#0: conflicting server name "localhost" on 0.0.0.0:80, ignored 2016/02/20 14:59:07 [warn] 1056#0: conflicting server name "localhost" on 0.0.0.0:80, ignored 2016/02/20 15:10:57 [error] 1071#0: *4 open() "/usr/share/nginx/html/8080" failed (2: No such file or directory), client: クライアントIP, server: localhost, request: "GET /8080 HTTP/1.1", host: "IPアドレス"
log/unicorn.log
I, [2016-02-20T15:00:52.798560 #1480] INFO -- : Refreshing Gem list I, [2016-02-20T15:00:55.513668 #1480] INFO -- : unlinking existing socket=/home/ユーザー名/アプリ名/shared/tmp/unicorn.sock I, [2016-02-20T15:00:55.513847 #1480] INFO -- : listening on addr=/home/ユーザー名/アプリ名/shared/tmp/unicorn.sock fd=11 I, [2016-02-20T15:00:55.528440 #1483] INFO -- : worker=0 ready I, [2016-02-20T15:00:55.529611 #1480] INFO -- : master process ready I, [2016-02-20T15:00:55.541416 #1485] INFO -- : worker=1 ready I, [2016-02-20T15:00:55.546382 #1488] INFO -- : worker=2 ready
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/20 12:37