Q&A
awsからさくらのクラウドにサーバー移行しています。
awsのamazonLinaxでは正常に動作していました。
$bundle exec unicorn_rails -c config/unicorn.rb -E production -D
$sudo systemctl start nginx
上の二つのコマンドはエラーなしで実行できるのですが、ブラウザで確認すると
表示されていません。
![
環境
さくらのクラウド 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
$sudo systemctl start nginx
エラー
2016/02/21 09:55:02 [error] 3988#0: *1 connect() to unix:/home/ユーザー名/アプリ名/tmp/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: ローカルip, server: 127.0.0.1, request: "GET /api/v1/music_threads HTTP/1.1", upstream: "http://unix:/home/ユーザー名/アプリ名/tmp/unicorn.sock:/api/", host: "ipアドレス"
設定ファイル
/etc/nginx/conf.d/local.conf
upstream unicorn { server unix:/home/ユーザー名/アプリ名/tmp/unicorn.sock; } server { listen 80 default_server; 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; #proxy_pass http://ipアドレス; } }
config/unicorn.rb
rails_root = File.expand_path('../../shared', __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}/tmp/unicorn.sock" pid "#{rails_root}/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/nginx.conf
user root; worker_processes 1; worker_rlimit_nofile 20480; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; # --- add-- include /etc/nginx/sites-enabled/*; }
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2016/02/26 08:51