2014-05-23 38 views
1

在使用nginx并解决所有错误时,出现错误。但是应用程序在生产服务器上以开发模式运行。麒麟,nginx连接在rails中被拒绝4

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" 

回答

1

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

在麒麟的conf文件使用:

listen "127.0.0.1:8080" 

在nginx的的c​​onf文件使用:

upstream app_server { 
    server 127.0.0.1:8080; 
} 
+0

端口号为8080有必要吗? –

+1

为什么'server 127.0.0.1:8080'而不是'server unix:/ tmp/unicorn.sample_app.sock'? – tvieira