【问题标题】:unicorn, nginx connection refused in rails 4独角兽,nginx连接在rails 4中被拒绝
【发布时间】:2014-05-23 10:02:39
【问题描述】:

在使用 nginx 并解决所有错误时,我遇到了错误。但应用程序在生产服务器上以开发模式运行。

Nginx 配置

pid /tmp/nginx.pid;
error_log /home/vagrant/app/sample_app/shared/log/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # "on" if nginx worker_processes > 1
}

http {
  include mime.types;
  default_type application/octet-stream;
  access_log  /home/vagrant/app/sample_app/shared/log/nginx.access.log combined;
  sendfile on;
  tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
  tcp_nodelay off; # on may be better for some Comet/long-poll stuff

  # types_hash_max_size 2048;

  upstream app_server {
    server 192.168.33.10;
  }

  server {
    client_max_body_size 4G;
    server_name localhost;
    keepalive_timeout 600s;
    root /home/vagrant/app/sample_app/current;
    try_files $uri/index.html $uri.html $uri @app;

    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app_server;
    }

    # Rails error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /home/vagrant/app/sample_app/current;
    }
  }
}

独角兽配置

listen "/tmp/unicorn.sample_app.sock"
worker_processes 4
preload_app true
user 'vagrant'
root = "/home/vagrant/app/sample_app/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"

# listen "/tmp/unicorn.sample_app.sock"
worker_processes 2
timeout 30

# Force the bundler gemfile environment variable to
# reference the capistrano "current" symlink
before_exec do |_|
  ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile')
end

得到错误:-

connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.33.1, server: 192.168.33.10, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "192.168.33.10"

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 nginx capistrano unicorn


    【解决方案1】:

    您似乎在 unicorn.rbnginx.conf 文件中使用了错误的监听端口配置。上游 app_server 是独角兽服务器的连接套接字。

    在 unicorn conf 文件中使用:

    listen "127.0.0.1:8080"
    

    在 nginx 配置文件中使用:

    upstream app_server {
        server 127.0.0.1:8080;
    }
    

    【讨论】:

    • 需要8080端口吗?
    • 为什么是server 127.0.0.1:8080 而不是server unix:/tmp/unicorn.sample_app.sock
    猜你喜欢
    • 2015-10-25
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 2020-09-16
    • 2021-01-16
    • 1970-01-01
    • 2015-09-27
    相关资源
    最近更新 更多