我有一个来自Azure服务的Ubuntu服务器,我想在rails应用程序上运行我的所有ruby。为此,我使用NGINX和UNICORN以及RAINBOWS!
我在rails项目上设置ruby用于生产并尝试运行它。我可以看到请求到达但是答案花了太长时间。有时候我甚至会错过时间。
我真的需要有关如何正确设置服务器的帮助。是否有任何教程,文档甚至是你们的提示(y'所有人总是保存我的屁股)可以帮助我使这台服务器工作?
这是我的ngnx配置文件
upstream nutrimais {
server unix:/tmp/nutrimais.sock;
}
server {
listen 80;
server_name dev.mydomain.com.br;
server_name www.mydomain.com.br;
server_name mydomain.com.br;
location / {
autoindex on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://nutrimais; # match the name of upstream directive
# time out settings
proxy_connect_timeout 159s;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_pass_header Set-Cookie;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_ignore_headers Cache-Control Expires;
proxy_set_header Referer $http_referer;
proxy_set_header Host $host;
proxy_set_header Cookie $http_cookie;
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;
}
}
这是我的彩虹!配置
Rainbows! do
use :ThreadSpawn # concurrency model to use
worker_connections 400
keepalive_timeout 0 # zero disables keepalives entirely
client_max_body_size 5*1024*1024 # 5 megabytes
keepalive_requests 666 # default:100
client_header_buffer_size 2 * 1024 # 2 kilobytes
end
@dir = File.expand_path(File.dirname(__FILE__)) + "/.."
worker_processes 1
working_directory @dir
timeout 30
listen File.join('/tmp/nutrimais.sock')
preload_app true# if ENV['RAILS_ENV'] != 'development'
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
check_client_connection false
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
这是一个耗时太长的请求日志
I, [2016-01-20T17:25:17.297122 #9] INFO -- : Started GET "/menus" for 127.0.0.1 at 2016-01-20 17:25:17 +0000
I, [2016-01-20T17:25:17.580380 #9] INFO -- : Processing by MenusController#index as HTML
D, [2016-01-20T17:25:17.904933 #9] DEBUG -- : [1m[36mMenu Load (322.3ms)[0m [1mSELECT `menus`.* FROM `menus` ORDER BY created_at DESC[0m
I, [2016-01-20T17:25:20.006674 #9] INFO -- : Started GET "/menus" for 127.0.0.1 at 2016-01-20 17:25:20 +0000
I, [2016-01-20T17:25:20.102991 #9] INFO -- : Started GET "/menus" for 127.0.0.1 at 2016-01-20 17:25:20 +0000
I, [2016-01-20T17:25:20.411379 #9] INFO -- : Processing by MenusController#index as HTML
I, [2016-01-20T17:25:22.172944 #9] INFO -- : Processing by MenusController#index as HTML
D, [2016-01-20T17:25:22.498899 #9] DEBUG -- : [1m[35mMenu Load (324.0ms)[0m SELECT `menus`.* FROM `menus` ORDER BY created_at DESC
D, [2016-01-20T17:25:23.059756 #9] DEBUG -- : [1m[36mMenu Load (884.2ms)[0m [1mSELECT `menus`.* FROM `menus` ORDER BY created_at DESC[0m
I, [2016-01-20T17:25:45.530393 #9] INFO -- : Rendered menus/index.html.erb within layouts/application (27948.1ms)
I, [2016-01-20T17:25:45.534684 #9] INFO -- : Completed 200 OK in 27954ms (Views: 27630.4ms | ActiveRecord: 322.3ms)
I, [2016-01-20T17:25:52.230905 #9] INFO -- : Rendered menus/index.html.erb within layouts/application (30055.5ms)
I, [2016-01-20T17:25:52.234927 #9] INFO -- : Completed 200 OK in 30062ms (Views: 29175.4ms | ActiveRecord: 884.2ms)
I, [2016-01-20T17:26:00.640179 #9] INFO -- : Rendered menus/index.html.erb within layouts/application (38465.6ms)
I, [2016-01-20T17:26:00.643772 #9] INFO -- : Completed 200 OK in 40232ms (Views: 38145.8ms | ActiveRecord: 324.0ms)
I, [2016-01-20T17:31:51.678765 #9] INFO -- : Started GET "/" for 127.0.0.1 at 2016-01-20 17:31:51 +0000
I, [2016-01-20T17:31:52.827556 #9] INFO -- : Started GET "/" for 127.0.0.1 at 2016-01-20 17:31:52 +0000
I, [2016-01-20T17:31:53.144345 #9] INFO -- : Processing by PostsController#index as HTML
I, [2016-01-20T17:31:54.117563 #9] INFO -- : Processing by PostsController#index as HTML
D, [2016-01-20T17:31:54.836516 #9] DEBUG -- : [1m[36mPost Load (702.9ms)[0m [1mSELECT `posts`.* FROM `posts` ORDER BY created_at DESC[0m
D, [2016-01-20T17:31:54.871071 #9] DEBUG -- : [1m[35mPost Load (735.0ms)[0m SELECT `posts`.* FROM `posts` ORDER BY created_at DESC
I, [2016-01-20T17:31:59.274495 #9] INFO -- : Rendered posts/index.html.erb within layouts/application (5145.7ms)
I, [2016-01-20T17:31:59.281284 #9] INFO -- : Completed 200 OK in 6137ms (Views: 3911.2ms | ActiveRecord: 1251.6ms)
I, [2016-01-20T17:31:59.363025 #9] INFO -- : Rendered posts/index.html.erb within layouts/application (5229.2ms)
I, [2016-01-20T17:31:59.368484 #9] INFO -- : Completed 200 OK in 5248ms (Views: 3951.1ms | ActiveRecord: 1294.4ms)
因为你可以看到它只是渲染页面5秒钟。