遵循rails一个应用程序点击部署。 数据库做得很好,即使我检查轨道控制台一切工作正常。
Ruby版本是2.3.0,rails版本是5.0.1
但是,当我点击IP地址,它会给出一个错误超时
在检查独angular兽日志我得到
/usr/local/rvm/gems/ruby-2.2.1/gems/unicorn-5.0.1/bin/unicorn:126:in `<top (required)>' /usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `load' /usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `<main>' /usr/local/rvm/gems/ruby-2.2.1@global/bin/ruby_executable_hooks:15:in `eval' /usr/local/rvm/gems/ruby-2.2.1@global/bin/ruby_executable_hooks:15:in `<main>' E, [2017-02-26T15:47:18.969274 #9861] ERROR -- : reaped #<Process::Status: pid 11928 exit 1> worker=2 I, [2017-02-26T15:47:18.969471 #9861] INFO -- : worker=2 spawning... I, [2017-02-26T15:47:18.974112 #11942] INFO -- : worker=2 spawned pid=11942 I, [2017-02-26T15:47:18.978540 #11936] INFO -- : Refreshing Gem list I, [2017-02-26T15:47:18.986558 #11938] INFO -- : Refreshing Gem list
和nginx错误是
017/02/26 15:34:17 [error] 18564#0: *31 connect() to unix:/var/run/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 121.52.156.57, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock:/", host: "188.166.157.124" 2017/02/26 15:35:42 [error] 32360#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.155.34.115, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124" 2017/02/26 15:42:38 [error] 6296#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.152.140.90, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"
unicorn.conf
listen "unix:/var/run/unicorn.sock" worker_processes 4 user "rails" working_directory "/home/rails/company_startup" pid "/var/run/unicorn.pid" stderr_path "/var/log/unicorn/unicorn.log" stdout_path "/var/log/unicorn/unicorn.log"
ps aux | grep unicor
rails 4751 18.0 4.2 172880 21516 ? R 14:59 0:00 unicorn worker[2] -D -c /etc/unicorn.conf -E production rails 4757 0.0 4.1 172404 20972 ? Rl 14:59 0:00 unicorn worker[3] -D -c /etc/unicorn.conf -E production rails 4760 0.0 2.9 159860 14568 ? Rl 14:59 0:00 unicorn worker[1] -D -c /etc/unicorn.conf -E production root 4764 0.0 0.1 11712 620 pts/0 S+ 14:59 0:00 grep --color=auto unicorn root 20463 0.4 2.6 146740 13176 ? Sl 04:32 2:48 unicorn master -D -c /etc/unicorn.conf -E production
这里的nginx文件:
upstream app_server { server unix:/var/run/unicorn.sock fail_timeout=0;
}
server { listen 80; root /home/rails/company_startup/public; server_name _; index index.htm index.html; client_max_body_size 1M; location / { try_files $uri/index.html $uri.html $uri @app; } location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ { try_files $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; } }
这听起来像是一个独角兽重启问题。 你说你不使用capistrano。 你如何部署你的应用程序?
编辑
独角兽使用多进程架构更好地利用可用的资源。 当它启动时,工作者加载ruby环境,然后派生处理请求的工作人员。 主人从不处理请求,总是工人。
当工作人员花费太长时间时,主人可以杀死它并重新启动一名新工人。
你似乎使用4名工人。 我不知道你的水滴的大小,但似乎主人不能再启动工人。 你能告诉我你的液滴(CPU和内存)的大小吗?
我会安装独角兽杀手宝石,并再次测试应用程序。 这应该比麒麟主人更有效地重新启动你的工人。
编辑2:如果这不起作用,你可以尝试用你的nginx conf文件替换你的上游行:
upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }
这在你的独角兽conf文件中:
listen "127.0.0.1:8080
然后重新启动nginx然后独角兽。
编辑3:
我想我明白了
你能不能改变你的文件是这样的:
unicorn.conf
listen "/var/run/unicorn.sock" worker_processes 4 user "rails" working_directory "/home/rails/company_startup" pid "/var/run/unicorn.pid" stderr_path "/var/log/unicorn/unicorn.log" stdout_path "/var/log/unicorn/unicorn.log"
Nginx文件
upstream app_server { server unix:/var/run/unicorn.sock fail_timeout=0; } server { listen 80; root /home/rails/company_startup/public; server_name <PLEASE PUT YOUR SERVER NAME>; index index.htm index.html; client_max_body_size 1M; location / { try_files $uri/index.html $uri.html $uri @app; } location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ { try_files $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; } }
重新启动独角兽(确保更换<>之间的值)
kill -s QUIT $(< /var/run/unicorn.pid) bundle exec unicorn -c <PATH TO unicorn.conf FILE> -E <RAILS ENVIRONMENT> -D
然后重新启动nginx
sudo service nginx restart
看看它是否有效。