実現したいこと
現在、転職活動用のポートフォリオ制作のため、Railsアプリをnginx, pumaを使いAWSにてデプロイを行おうとしております。
ブラウザでipアドレスを開いたところ、502 Bad Gatewayのエラー画面になり、nginxのエラーログを確認したところ、下記のエラーが出ていました。自身で調べましたが解決方法がわからず、ご教授いただきますと幸いです。
$ cat log/nginx.error.log
2023/04/28 01:13:33 [error] 9993#9993: *2572 connect() to unix:/var/www/portfolio/tmp/sockets/puma.sock failed (111: Connection refused) while connecting to upstream, client: 126.85.210.84, server: portfolio.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/portfolio/tmp/sockets/puma.sock:/", host: "35.79.218.129"
nginx
nginx.conf
1user nginx; 2worker_processes auto; 3error_log /var/log/nginx/error.log; 4pid /run/nginx.pid; 5 6# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. 7include /usr/share/nginx/modules/*.conf; 8 9events { 10 worker_connections 1024; 11} 12 13http { 14 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 15 '$status $body_bytes_sent "$http_referer" ' 16 '"$http_user_agent" "$http_x_forwarded_for"'; 17 18 access_log /var/log/nginx/access.log main; 19 20 sendfile on; 21 tcp_nopush on; 22 tcp_nodelay on; 23 keepalive_timeout 65; 24 types_hash_max_size 4096; 25 26 include /etc/nginx/mime.types; 27 default_type application/octet-stream; 28 29 # Load modular configuration files from the /etc/nginx/conf.d directory. 30 # See http://nginx.org/en/docs/ngx_core_module.html#include 31 # for more information. 32 include /etc/nginx/conf.d/*.conf; 33 34 gzip on; 35 gzip_http_version 1.0; 36 gzip_proxied any; 37 gzip_min_length 500; 38 gzip_disable "MSIE [1-6]\."; 39 gzip_types text/plain text/xml text/css 40 text/comma-separated-values 41 text/javascript application/x-javascript 42 application/atom+xml; 43}
nginx/conf.d/portfolio.conf
1upstream puma { 2 server unix:/var/www/portfolio/tmp/sockets/puma.sock; 3} 4 5server { 6 server_name portfolio.com; 7 8 keepalive_timeout 0; 9 10 access_log /var/log/nginx/portfolio.access.log main; 11 client_max_body_size 4G; 12 13 root /var/www/portfolio/public; 14 location ~ .*\.(swf|SWF|ico|ICO|jar|txt|gz|js) { 15 root /var/www/portfolio/public; 16 expires 15m; 17 break; 18 } 19 location ~ ^\/fonts\/* { 20 root /var/www/portfolio/public; 21 expires 15m; 22 break; 23 } 24 location ~ ^\/assets\/* { 25 root /var/www/portfolio/public; 26 break; 27 } 28 location ~ ^\/favicon\/* { 29 root /var/www/portfolio/public; 30 break; 31 } 32 location = /manifest.json { 33 root /var/www/portfolio/public; 34 break; 35 } 36 location / { 37 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 38 proxy_set_header Host $http_host; 39 proxy_redirect off; 40 41 #auth_basic "Restricted"; 42 #auth_basic_user_file /etc/nginx/.htpasswd; 43 #if ($http_x_forwarded_proto = "http") { 44 #rewrite ^(.*) https://$server_name$1 45 #break; 46 #} 47 proxy_pass http://puma; 48 } 49}
pumaの設定ファイル
puma.rb
1max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 2min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 3threads min_threads_count, max_threads_count 4 5#port ENV.fetch("PORT") { 3000 } 6bind "unix:///var/www/portfolio/tmp/sockets/puma.sock" 7 8environment ENV.fetch("RAILS_ENV") { "development" } 9 10pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 11 12plugin :tmp_restart](url)
puma起動時の表示
Puma starting in single mode... * Puma version: 5.6.5 (ruby 2.7.6-p219) ("Birdie's Version") * Min threads: 5 * Max threads: 5 * Environment: development * PID: 10100 * Listening on unix:///var/www/portfolio/tmp/sockets/puma.sock Use Ctrl-C to stop
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/28 16:44
2023/04/29 00:49