Railsアプリケーションをデプロイしてアクセスすると、We're sorry, but something went wrong.
の502エラーでnginxのログを確認してみると、
connect() failed (111: Connection refused) while connecting to upstream
エラーになっていました。
調べてみると、unicorn.sock
あたりの設定だというのですが、見直しても間違っていないと思います。
他に原因があるのでしょうか?
解決策をいただけると助かります。
unicorn.rb
rails_root = File.expand_path('../../../', __FILE__) ENV['BUNDLE_GEMFILE'] = rails_root + "/Gemfile" worker_processes 2 timeout 30 preload_app true stderr_path File.expand_path('../../../../log/unicorn_stderr.log', __FILE__) listen "/var/www/RailsApp/current/tmp/sockets/.unicorn.sock" app_path = File.expand_path('../../../', __FILE__) shared_path = File.expand_path('../../../../shared/', __FILE__) 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
default.conf
error_log /var/www/RailsApp/current/log/nginx.error.log; access_log /var/www/RailsApp/current/log/nginx.access.log; client_max_body_size 2G; upstream app_server { server unix:/var/www/RailsApp/current/tmp/sockets/.unicorn.sock; } server { listen 443 ssl; server_name ドメイン名; keepalive_timeout 5; root /var/www/RailsApp/current/public; try_files $uri/index.html $uri.html $uri @app; location @app { # HTTP headers proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://127.0.0.1:3000; } error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/RailsApp/current/public; } }
nginx.conf
user nginx; worker_processes 1; 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; keepalive_timeout 65; include /etc/nginx/conf.d/default.conf; }
行ったこと
UNIXドメインソケットではなく、INETドメインソケットを利用する方法
teratail - nginxで(111: Connection refused)エラーがでます。
環境
CentOS7
nginx
unicorn

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/10 15:53
2018/05/10 16:01