502错误网关错误Nginx connect()到unix:/tmp/unicorn.sock失败

前端之家收集整理的这篇文章主要介绍了502错误网关错误Nginx connect()到unix:/tmp/unicorn.sock失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是我关于服务器故障的第一个问题.我在搜索网络时找不到解决方案.

我正在运行一个运行Nginx的OpenBSD服务器,我没有设置,这是在浏览器中抛出502 Bad Gateway错误. Nginx错误日志显示错误

014/04/29 09:43:49 [error] 5236#0: *263 connect() to unix:/tmp/unicorn.sock Failed (61: Connection refused) while connecting to upstream,client: ###.###.###.###,server:,request: "GET / HTTP/1.1",upstream: "http://unix:/tmp/unicorn.sock:/",host: "sub.domain.com"

这是Nginx.conf的内容

user _Nginx;
worker_processes 2;
pid /var/run/Nginx.pid;
error_log  /var/log/httpd.err debug;

events {
    worker_connections  1024;
}

http {
  include       /etc/Nginx/mime.types;
  default_type  application/octet-stream;
  log_format access '$remote_addr - $remote_user [$time_local]  '
                    '"$request" $status $body_bytes_sent $bytes_sent '
                    '"$http_referer" "$http_user_agent" "$sent_http_content_type"';

  access_log /var/log/httpd.log access;
  upload_progress proxied 1m;

  sendfile        on;
  server_name_in_redirect off;

  client_body_timeout   120;
  client_header_timeout 120;
  keepalive_timeout     20;
  send_timeout          120;

  upstream mongrel {
    server unix:/tmp/unicorn.sock;

  }

  gzip on;
  gzip_vary on;
  gzip_min_length  0;
  gzip_comp_level  6;
  gzip_buffers     16 8k;
  gzip_proxied     any;
  gzip_types       text/plain text/javascript text/css text/stylesheet application/x-javascript application/javascript;
  gzip_disable     "MSIE [1-6]\.";

  client_max_body_size 128000M;
  client_body_buffer_size 512k;

  ssl_session_timeout  60m;
  ssl_protocols  SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH;
  ssl_prefer_server_ciphers   on;
  ssl_session_cache shared:SSL:1m;
  ssl_certificate /etc/ssl/server.crt;
  ssl_certificate_key /etc/ssl/private/server.key;

  server {
    listen 80;
    listen [::]:80;
    listen 443 default ssl;
    listen [::]:443 default ssl;
    charset utf-8;

    root /var/sfta/current/public;

    location ~* ^/(message\/create|dropBox\/create|attachment\/create|attachments) {
      upload_pass @internal_upload;
      upload_resumable on;
      upload_pass_args on;
      upload_store /var/data/tmp;
      upload_state_store /var/data/tmp/resume;
      upload_store_access user:rw group:rw all:rw;
      chunked_transfer_encoding on;

      proxy_redirect     off;
      proxy_set_header   Host               $host;
      proxy_set_header   X-Real-IP          $remote_addr;
      proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
      proxy_set_header   X_Forwarded_Proto  $scheme;

      if ($request_method != POST) {
        proxy_pass http://mongrel;
        break;
      }

      # Set specified fields in request body
      upload_set_form_field $upload_field_name.name         "$upload_file_name";
      upload_set_form_field $upload_field_name.content_type "$upload_content_type";
      upload_set_form_field $upload_field_name.path         "$upload_tmp_path";
      upload_aggregate_form_field "$upload_field_name.sha1" "$upload_file_sha1";
      upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";

      upload_max_output_body_len 0;
      upload_pass_form_field "^authenticity_token$|message|dropBox";
      upload_cleanup 400 404 499 500-505;

      # track uploads in the 'proxied' zone
      # remember connections for 30s after they finished
      track_uploads proxied 120s;
    }

    location ~* ^/(send|messages) {
      rewrite ^(.*)$/message redirect;
    }

    location / {
      proxy_pass         http://mongrel;
      proxy_redirect     off;
      proxy_set_header   Host               $host;
      proxy_set_header   X-Real-IP          $remote_addr;
      proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
      proxy_set_header   X_Forwarded_Proto  $scheme;
      proxy_read_timeout 120;
      proxy_connect_timeout 120;

      # track uploads in the 'proxied' zone
      # remember connections for 30s after they finished
      track_uploads proxied 120s;
    }

    location @internal_upload {
      proxy_pass         http://mongrel;
      proxy_redirect     off;
      proxy_set_header   Host               $host;
      proxy_set_header   X-Real-IP          $remote_addr;
      proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
      proxy_set_header   X_Forwarded_Proto  $scheme;
      proxy_read_timeout 120;
      proxy_connect_timeout 120;
    }

    location ~* ^/send {
      rewrite ^(.*)$/message redirect;
    }

    location ^~ /files/ {
      alias /var/data/files/;
      chunked_transfer_encoding on;
      post_action @protected_done;
      if_modified_since off;
      gzip off;
      internal;
    }

    location @protected_done {
      internal;
      proxy_pass         http://mongrel;
      proxy_set_header   RateBytes        $body_bytes_sent;
      proxy_set_header   Host             $host;
      proxy_set_header   X-Real-IP        $remote_addr;
      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
      proxy_pass_request_body off;
      proxy_pass_request_headers off;
    }

    location ^~ /images/custom {
      alias /var/data/assets/images;
    }

    location ~* /(javascripts|stylesheets|images)/.*\.(ico|css|gif|js|jp?g|png)(\?[0-9]+)?${
      access_log off;
      expires 1w;
      break;
    }

    location = /favicon.ico {
       alias /var/data/assets/images/favicon.ico;
       access_log off;
    }

    location = /alive {
      access_log off;
      return 200;
    }

    location ^~ /progress {
      access_log off;
      report_uploads proxied;
      upload_progress_json_output;
    }

    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /500.html;
  }
}

我对Nginx的经验很少.任何帮助是极大的赞赏.

附加信息:

unicorn.rb

listen '/tmp/unicorn.sock'
worker_processes 2
working_directory "/var/sfta/current"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn.log"
timeout 120
preload_app true

before_fork do |server,worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!

  old_pid = '/var/run/unicorn.pid.oldbin'
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT",File.read(old_pid).to_i)
    rescue Errno::ENOENT,Errno::ESRCH
      # someone else did our job for us
    end
  end

  # Throttle the master from forking too quickly by sleeping.
  sleep 1
end

after_fork do |server,worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection

  worker.user('_sfta','_sfta') if Process.euid == 0
end
最佳答案
这意味着Nginx尝试使用UNIX套接字/tmp/unicorn.sock将您的流发送到应用程序.但似乎这个套接字不存在.

Unicorn是一个Ruby服务器.您需要使用指定套接字/tmp/unicorn.sock的unicorn启动ruby应用程序.

原文链接:https://www.f2er.com/nginx/435509.html

猜你在找的Nginx相关文章