简体   繁体   English

独角兽,nginx连接在rails 4中被拒绝

[英]unicorn, nginx connection refused in rails 4

While using the nginx and resolving all the errors, i am getting the error. 在使用nginx并解决所有错误时,我遇到了错误。 But the application is running in development mode on production server. 但是该应用程序正在生产服务器上以开发模式运行。

Nginx configuration 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;
    }
  }
}

Unicorn Configuration 独角兽配置

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

Getting error:- 收到错误:

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"

It seems like that you are using the wrong configuration for listening port in unicorn.rb and nginx.conf file. 似乎您在unicorn.rbnginx.conf文件中使用了错误的配置来侦听端口。 The upstream app_server is the connection socket to unicorn server. 上游app_server是与unicorn服务器的连接套接字。

In unicorn conf file use: 在独角兽conf文件中使用:

listen "127.0.0.1:8080"

In nginx conf file use: 在nginx conf文件中使用:

upstream app_server {
    server 127.0.0.1:8080;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM