nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { upstream unicorn { # nginxとunicornの連携 # unicorn.rbで設定したunicorn.sockを指定 server unix:dir/tmp/sockets/unicorn.sock; } server { listen 8208; server_name localhost; #root /path/to/app/static; location / { # 静的ファイルが存在しなかった時はUnicornにproxy #if (!-f $request_filename) { # proxy_pass http://unicorn_server; # break; #} } } }
unicorn.conf
# Railsのルートパスを求める。(RAILS_ROOT/config/unicorn.rbに配置している場合。) rails_root = File.expand_path('../../', __FILE__) # RAILS_ENVを求める。(RAILS_ENV毎に挙動を変更したい場合に使用。今回は使用しません。) # rails_env = ENV['RAILS_ENV'] || "development" # 追記に記載してます。入れた方がいいです。 ENV['BUNDLE_GEMFILE'] = rails_root + "/Gemfile" # Unicornは複数のワーカーで起動するのでワーカー数を定義 # サーバーのメモリなどによって変更すること。 worker_processes 2 # 指定しなくても良い。 # Unicornの起動コマンドを実行するディレクトリを指定します。 # (記載しておけば他のディレクトリでこのファイルを叩けなくなる。) working_directory rails_root # 接続タイムアウト時間 timeout 30 # Unicornのエラーログと通常ログの位置を指定。 stderr_path File.expand_path('../../log/unicorn_stderr.log', __FILE__) stdout_path File.expand_path('../../log/unicorn_stdout.log', __FILE__) # Nginxで使用する場合は以下の設定を行う。 listen File.expand_path('../../tmp/sockets/unicorn.sock', __FILE__) # とりあえず起動して動作確認をしたい場合は以下の設定を行う。 # ※「backlog」や「tcp_nopush」の設定もあるけど、よくわかって無い。 listen 8080 # プロセスの停止などに必要なPIDファイルの保存先を指定。 pid File.expand_path('../../tmp/pids/unicorn.pid', __FILE__) # 基本的には`true`を指定する。Unicornの再起動時にダウンタイムなしで再起動が行われる。 preload_app true # 効果なしとの記事を見たので、コメントアウト。 # GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true # USR2シグナルを受けると古いプロセスを止める。 # 後述するが、記述しておくとNginxと連携する時に良いことがある。 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 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, 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
unicornでportを8080にした場合
nginxでのportを8080にした場合
bind() to 0.0.0.0:8208 failed (48: Address already in use)
どちらを設定したらよろしいのでしょうか?
unicorn側でsocketだけを生成し
nginx側でsocketをつなぐ処理を書けばよろしいのでしょうか?
自分のもともと認識が違うのでしょうか?
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/20 16:01