前提・実現したいこと
Nginxをリバースプロキシとして使用し、RailsのAPサーバであるPumaにUNIXドメイン連携したい。
発生している問題・エラーメッセージ
ブラウザからHTTPSアクセスしてもNginxのページまでしか届かない。
--> ps aux | grep puma でプロセスを確認したところ、http://localhost:3000と表示された
しかしrails sを実行するとListening on unix:///opt/sp-aws-educate/tmp/sockets/puma.sockと表示される。ここが一致すればおそらく解消されるはずだが、、どのようにすれば良いか分かりません。
追記
rails s -d で起動すると、
puma 5.3.2 (tcp://localhost:3000)
rails sで起動して、別ターミナルでpsを確認すると
puma 5.3.2 (unix:///opt/rails-app-name/tmp/sockets/puma.sock)
という結果になった。
-dオプションをつけるか付けないかの違いでなぜ受付ポートに差が出てしまうのか、不明です。。
該当のソースコード
Nginx系
/etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; 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; }
/etc/nginx/conf.d/default.conf
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
/etc/nginx/conf.d/https.conf
map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 443 ssl http2; server_name XXX.com; location / { root /usr/share/nginx/html; index index.html index.htm; } ssl_protocols TLSv1.2; ssl_ciphers EECDH+AESGCM:EECDH+AES; ssl_ecdh_curve prime256v1; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_certificate /etc/letsencrypt/live/XXX.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/XXX.com/privkey.pem; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
/etc/nginx/conf.d/rails-app-name.conf
upstream rails-app-name { server unix:///opt/rails-app-name/tmp/sockets/puma.sock; } server { listen 80; server_name XXX.com; root /opt/rails-app-name/public; try_files $uri/index.html $uri.html $uri @rails-app-name; location @rails-app-name { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://rails-app-name; } error_page 500 502 503 504 /500.html; location = /500.html { root /opt/rails-app-name/public; } }
/var/log/nginx/error.log
[error] connect() to unix:///opt/rails-app-name/tmp/sockets/puma.sock failed (111: Connection refused) while connecting to upstream, client: XXX.XXX.XXX.XXX, server: XXX.com, request: "GET /wp-admin/install.php?step=1 HTTP/1.1", upstream: "http://unix:///opt/rails-app-name/tmp/sockets/puma.sock:/wp-admin/install.php?step=1", host: "XXX.com"
/opt/rails-app-name/config/puma.rb
# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # #port ENV.fetch("PORT") { 3000 } bind "unix:///opt/rails-app-name/tmp/sockets/puma.sock" # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # # preload_app! # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart
`
試したこと
- nginxで(111: Connection refused)が出て、アクセスできないです。
https://teratail.com/questions/308033
--> ps aux | grep puma でプロセスを確認したところ、http://localhost:3000と表示された
しかしrails sを実行するとListening on unix:///opt/sp-aws-educate/tmp/sockets/puma.sockと表示される。ここが一致すればおそらく解消されるはずだが、、どのようにすれば良いか分かりません。
補足情報(FW/ツールのバージョンなど)
- cent os 8.4.2105
- ruby 2.6.3p62
- Rails 6.1.4
- Puma 5.3.2 (ruby 2.6.3-p62) ("Sweetnighter")
あなたの回答
tips
プレビュー