簡體   English   中英

rails puma.sock 在使用 Nginx 應用服務器連接到上游時失敗(111:連接被拒絕)

[英]rails puma.sock failed (111: Connection refused) while connecting to upstream with Nginx app server

2022/07/13 10:24:33 [error] 617#617: *178 connect() to unix:/var/www/tuma_mizigo/shared/tmp/sockets/puma.sock failed (111: Unknown error) while connecting to upstream, client: 40.97.61.4, server: tumamizigo.com, request: "GET /couriers HTTP/1.1", upstream: "http://unix:/var/www/tuma_mizigo/shared/tmp/sockets/puma.sock:/couriers", host: "19.191.221.98"

請注意正在運行的 puma systemd 服務。 這是sudo systemctl status puma_tuma_mizigo_production.service的輸出

● puma_tuma_mizigo_production.service - Puma HTTP Server for tuma_mizigo (production)
     Loaded: loaded (/etc/systemd/system/puma_tuma_mizigo_production.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-07-13 12:10:16 UTC; 40min ago
   Main PID: 16043 (ruby)
      Tasks: 17 (limit: 1145)
     Memory: 217.6M
        CPU: 3.824s
     CGroup: /system.slice/puma_tuma_mizigo_production.service
             ├─16043 "puma 5.6.4 (unix:///var/www/tuma_mizigo/shared/tmp/sockets/puma.sock)" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
             ├─16303 "puma: cluster worker 0: 16043" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             └─16304 "puma: cluster worker 1: 16043" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >

Jul 13 12:10:16 ip-172-31-42-199 systemd[1]: puma_tuma_mizigo_production.service: Deactivated successfully.
Jul 13 12:10:16 ip-172-31-42-199 systemd[1]: Stopped Puma HTTP Server for tuma_mizigo (production).
Jul 13 12:10:16 ip-172-31-42-199 systemd[1]: puma_tuma_mizigo_production.service: Consumed 7.400s CPU time.
Jul 13 12:10:16 ip-172-31-42-199 systemd[1]: Started Puma HTTP Server for tuma_mizigo (production).

cat /var/www/tuma_mizigo/shared/tmp/pids/puma.pid顯示工作 pid: 16043

cat /var/www/tuma_mizigo/shared/tmp/pids/puma.state輸出:

---
pid: 16043
running_from: "/var/www/tuma_mizigo/releases/20220713095512"

這是我的/var/www/tuma_mizigo/shared/puma.rb文件:

#!/usr/bin/env puma

directory '/var/www/tuma_mizigo/current'
rackup "/var/www/tuma_mizigo/current/config.ru"
environment 'production'

tag ''

pidfile "/var/www/tuma_mizigo/shared/tmp/pids/puma.pid"
state_path "/var/www/tuma_mizigo/shared/tmp/pids/puma.state"

threads 0,16

bind 'unix:///var/www/tuma_mizigo/shared/tmp/sockets/puma.sock'

workers 2
restart_command 'bundle exec puma'

prune_bundler

on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = ""
end

Systemd Puma 服務配置

這是我的/etc/systemd/system/puma_tuma_mizigo_production.service文件:

[Unit]
Description=Puma HTTP Server for tuma_mizigo (production)
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/var/www/tuma_mizigo/current
# Support older bundler versions where file descriptors weren't kept
# See https://github.com/rubygems/rubygems/issues/3254
ExecStart=/home/ubuntu/.rvm/bin/rvm default do bundle exec --keep-file-descriptors puma -C /var/www/tuma_mizigo/shared/puma.rb
ExecReload=/bin/kill -USR1 $MAINPID
StandardOutput=append:/var/www/tuma_mizigo/shared/log/puma_access.log
StandardError=append:/var/www/tuma_mizigo/shared/log/puma_error.log

Restart=always
RestartSec=1

SyslogIdentifier=puma

[Install]
WantedBy=multi-user.target

Nginx 配置

這是我的/etc/nginx/sites-available/tuma_mizigo_production文件:

upstream puma_tuma_mizigo_production {
  server unix:/var/www/tuma_mizigo/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
    if ($host = tumamizigo.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  listen 80 default_server;
  listen [::]:80 default_server;

  server_name tumamizigo.com;
    return 404; # managed by Certbot
}


server {
    if ($host = www.tumamizigo.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name www.tumamizigo.com;
    listen 80;
    return 404; # managed by Certbot
}


server {
  listen [::]:443 ssl ipv6only=on;
  listen 443 ssl;
  ssl_certificate /etc/letsencrypt/live/tumamizigo.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/tumamizigo.com/privkey.pem;
  server_name  tumamizigo.com;
  root /var/www/tuma_mizigo/current/public;
  try_files $uri/index.html $uri @puma_tuma_mizigo_production;

  client_max_body_size 4G;
  keepalive_timeout 10;

  error_page 500 502 504 /500.html;
  error_page 503 @503;

  location @puma_tuma_mizigo_production {
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Forwarded-Proto https;
    proxy_pass http://puma_tuma_mizigo_production;
    # limit_req zone=one;
    access_log /var/www/tuma_mizigo/shared/log/nginx.access.log;
    error_log /var/www/tuma_mizigo/shared/log/nginx.error.log;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location = /50x.html {
    root html;
  }

  location = /404.html {
    root html;
  }

  location @503 {
    error_page 405 = /system/maintenance.html;
    if (-f $document_root/system/maintenance.html) {
      rewrite ^(.*)$ /system/maintenance.html break;
    }
    rewrite ^(.*)$ /503.html break;
  }

  if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }
}

日志說什么? 查看journalctl -u puma_tuma_mizigo_productionjournalctl -u nginx

另外,您在套接字文件上設置了什么權限? 您可以使用ls -l /var/www/tuma_mizigo/shared/tmp/sockets/puma.sock檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM