前提
社員のメンタル管理をするwebアプリケーションを作成
rails5+capistano3+nginx+Mysql+さくらVPS(centOs7)でのデプロイ
デプロイに関しての参考記事は以下の記事参考
[https://qiita.com/ryo2132/items/f62690f0b16ec11270fe]
[https://qiita.com/ryo2132/items/03f5f52b43742f5aef10]
当方、Java周りは②年弱の経験あり、しかしruby,Linuxは1〜2ヶ月の初心者故、
技術的な知識不足があることは重々承知の上で質問させていただきたく思います。
実現したいこと
同じ動作(画面遷移・メニュー表示等)をさせるときには同じ挙動をするようにしたい。
発生している問題・エラーメッセージ
production環境で同じ画面の呼び出しなのに通常の挙動とエラーになる時がある。
簡単に話すと
①ユーザがログインから認証
→②管理画面に遷移→
→③メニューから上司の在席管理をする画面にlink_to
→④サーバー内でDBに事前登録した予定を取得し表示する
というアクセスが有った場合、正常に画面表示することもあれば③→④の過程で505エラーも起こります。(メニューの画面遷移、更新共に)
ちなみにdevelopment環境では正常に動きます。
rails等のキャッシュとかそういったものが悪さをしているのでしょうか?
それともproduction.rb等の設定がおかしいのでしょうか?
また、同じ挙動になるようにするにはどのように設定をする必要があったりしますでしょうか?
何卒、よろしくおねがいします。
/config/environments/production.rb Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = false # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = false # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = true # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options) config.active_storage.service = :local # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "lmane_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end ActionMailer::Base.smtp_settings = { address: 'smtp.gmail.com', port: 587, user_name: 'XXXXXXXX@XXX.com', password: 'XXXXXX', authentication: 'plain', enable_starttls_auto: true }
config/unicorn/production.rb $worker = 2 $timeout = 30 $app_dir = "/var/www/hogehoge/current" $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid preload_app true before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if 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
[2018/09/30 10:45追記]
505のエラーログって、上記に書いた1つ目の記事の6−2
error_log /var/www/hoge_app/current/log/nginx.error.log;
access_log /var/www/hoge_app/current/log/nginx.access.log;
ここに出力されるという認識だったのですが、リアルタイムでここにログが載りません。
ここには最新のエラーログは残っていないのです。
エラーレベルが違うせいで表示されないのでしょうか?
それとも別の場所に設定されてしまっているのでしょうか?
以下が該当アプリ用のnginxの設定になります。(hoge.conf) error_log /var/www/hoge/current/log/nginx.error.log; access_log /var/www/hoge/current/log/nginx.access.log; client_max_body_size 2G; upstream app_server { server unix:/var/www/hoge/current/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name hogehoge.com; keepalive_timeout 5; root /var/www/hoge/current/public; try_files $uri/index.html $uri.html $uri @app; location @app { # HTTP headers 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; } error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/hoge/current/public; } }
[2018/09/30 15:41追記]
2018/09/30 15:38:30 [info] 2336#0: *210 client closed connection while waiting for request, client: 210.130.XXX.XX, server: 0.0.0.0:80 2018/09/30 15:39:31 [info] 2335#0: *217 client timed out (110: Connection timed out) while waiting for request, client: 210.130.XXX.XX, server: 0.0.0.0:80
[2018/09/30 17:20追記]
total used free shared buff/cache available Mem: 1015392 483236 229244 6876 302912 362924 Swap: 5242872 0 5242872
