我在ubuntu14.04上设置nginx和unicorn来访问我的rails应用程序!
但是,我访问了我的域名,Chrome已响应'连接被拒绝'
我不知道为什么......
如何解决此问题?
有我的nginx.conf和unicorn文件。
【nginx.conf】
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
#include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
【MyApp的-麒麟】(在/ etc / nginx的/ / MyApp的-麒麟启用位点)
upstream myapp.com {
#my rails app
server unix:/var/www/rails/myapp/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name myapp.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 35M;
proxy_pass http://myapp.com;
}
}
【unicorn.rb】(/无功/网络/轨道/ MyApp的/配置/ unicorn.rb)
worker_processes 2
listen File.expand_path('tmp/sockets/unicorn.sock', ENV['RAILS_ROOT'])
stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
preload_app true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{ server.config[:pid] }.oldbin"
unless old_pid == server.pid
begin
Process.kill :QUIT, File.read(old_pid).to_i
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
感谢您对我可怜的英语的耐心。
这是unicorn.log(/var/www/rails/myapp/log/unicorn.log)
I, [2015-09-05T18:17:20.590239 #10832] INFO -- : Refreshing Gem list
I, [2015-09-05T18:17:22.099133 #10832] INFO -- : unlinking existing socket=/var/www/rails/myapp/tmp/sockets/unicorn.sock
I, [2015-09-05T18:17:22.099389 #10832] INFO -- : listening on addr=/var/www/rails/myapp/tmp/sockets/unicorn.sock fd=11
I, [2015-09-05T18:17:22.115503 #10832] INFO -- : master process ready
I, [2015-09-05T18:17:22.118878 #10836] INFO -- : worker=0 ready
I, [2015-09-05T18:17:22.127008 #10839] INFO -- : worker=1 ready
这是nginx.log(/var/log/nginx/error.log)
nginx日志是无...
答案 0 :(得分:0)
如果您的错误是
position=1 and customer =...
尝试运行独角兽听
connect() failed (111: Connection refused) while connecting to upstream
而不是
listen /tmp/sockets/unicorn.sock
因为有时候nginx由于权限而无法读取该套接字文件。如果你在 tmp 文件夹中有套接字文件,那就相当安全了。同时将 NGINX 指向
listen File.expand_path('tmp/sockets/unicorn.sock', ENV['RAILS_ROOT'])
而不是
server unix:/tmp/sockets/unicorn.sock fail_timeout=0;
如果您仍然收到错误,请回复 快乐部署;)