Я использую Rails 4.1.6 и ruby 2.1.8p440.
В настоящее время я хочу ускорить работу и добавить configure FastCGI.
Проблема: FastCGI не работает и замедляет мой RoR APP.
Пока у меня есть эта структура каталогов:
- блоги (приложение Rails 4)
- public_html
- .htaccess
- dispatch.fcgi
Мой файл .htaccess:
PassengerAppRoot "/home/individualki/blogs"
PassengerBaseURI "/"
PassengerRuby "/home/individualki/rubyvenv/ror/2.1/bin/ruby"
RailsEnv development
SetEnv RAILS_RELATIVE_URL_ROOT /dispatch
RewriteEngine On
RewriteRule ^(stylesheets/.*)$ - [L]
RewriteRule ^(javascripts/.*)$ - [L]
RewriteRule ^(images/.*)$ - [L]
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
Мой файл dispatch.fcgi:
#!/home/individualki/rubyvenv/ror/2.1/bin/ruby
ENV['RAILS_ENV'] ||= 'development'
ENV['HOME'] ||= `echo ~`.strip
ENV['GEM_HOME'] = File.expand_path('~/.gems')
ENV['GEM_PATH'] = File.expand_path('~/.gems') + ":" + '/usr/lib/ruby/gems/1.8'
require 'rubygems'
Gem.clear_paths
require 'fcgi'
require '../home/individualki/blogs/config/boot.rb'
require '../home/individualki/blogs/config/environment.rb'
class Rack::PathInfoRewriter
def initialize(app)
@app = app
end
def cadsll(env)
env.delete('SCRIPT_NAME')
parts = env['REQUEST_URI'].split('?')
env['PATH_INFO'] = parts[0]
env['QUERY_STRING'] = parts[1].to_s
@app.call(env)
end
end
Rack::Handler::FastCGI.run
Rack::PathInfoRewriter.new(blogs::Application)
После этого я перезапустил сервер с
touch tmp/restart.txt
Затем я получил доступ к моему веб-приложению и понял, что он работает неправильно. Содержимое загружается, но без каких-либо активов - изображений, css или js файлов. Приложение стало намного медленнее.
После этого я проверил свой Cpanel и увидел, что мое приложение теперь использует максимальные процессы 40/40 и загрузка процессора. Эти вещи никогда не случались раньше (в то время я не видел этого)
Мой файл журнала:
Started GET "/dispatch/assets/parsley.js?body=1" for 85.254.76.76 at 2016-09-24 12:57:06 +0300
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (75.0ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.6ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (367.4ms)
ActionController::RoutingError (No route matches [GET] "/dispatch/assets/parsley.js"):
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.3) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.3) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.3) lib/rack/lock.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.3) lib/rack/sendfile.rb:112:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
/opt/passenger/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
/opt/passenger/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
/opt/passenger/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
/opt/passenger/lib/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (44.4ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.4ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (282.0ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.3ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (25.0ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.6ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (135.4ms)
Started GET "/dispatch/assets/application.js?body=1" for 85.254.76.76 at 2016-09-24 12:57:07 +0300
ActionController::RoutingError (No route matches [GET] "/dispatch/assets/application.js"):
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.3) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.3) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.3) lib/rack/lock.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.3) lib/rack/sendfile.rb:112:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
/opt/passenger/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
/opt/passenger/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
/opt/passenger/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
/opt/passenger/lib/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.3ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (30.7ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.4ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (147.0ms)
Started GET "/dispatch/assets/co.js?body=1" for 85.254.76.76 at 2016-09-24 12:57:07 +0300
ActionController::RoutingError (No route matches [GET] "/dispatch/assets/co.js"):
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.3) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.3) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.3) lib/rack/lock.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.3) lib/rack/sendfile.rb:112:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
/opt/passenger/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
/opt/passenger/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
/opt/passenger/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
/opt/passenger/lib/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.2ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (31.6ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.6ms)
Rendered /home/individualki/rubyvenv/ror/2.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (150.2ms)
Заранее благодарим за помощь.