質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
さくらのクラウド

さくらのクラウドは、さくらインターネット株式会社が提供するIaaS型のクラウドサービス。仮想化技術による柔軟性のあるカスタマイズを始め、様々な高機能を備えています。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

1回答

1899閲覧

rails+さくらVPSのproduction環境だと同じ動作でも同じ挙動をしない

ManaKuri09

総合スコア21

さくらのクラウド

さくらのクラウドは、さくらインターネット株式会社が提供するIaaS型のクラウドサービス。仮想化技術による柔軟性のあるカスタマイズを始め、様々な高機能を備えています。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2018/09/29 19:15

編集2018/09/30 08:21

前提

社員のメンタル管理をする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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

scsi

2018/09/29 23:06

505になった時のエラーログも書きましょう
ManaKuri09

2018/09/30 01:56

返信有難うございます。エラーログを参照してみたのですが、上記に書いたとおり、出力されなくて詰まっています。
scsi

2018/09/30 03:13

パーミッションのエラーで書き込めていないとかないですか?
ManaKuri09

2018/09/30 06:40

先程エラーログのレベルをinfo にしてみたら、追記のようなログが出力されました。
ManaKuri09

2018/09/30 06:43

PCとスマホと、両方接続して試しています。
scsi

2018/09/30 07:01

TimeoutしているのでTimeout値を長くしてみるなどの対応してみては如何でしょうか。またメモリは足りてますでしょうか。
ManaKuri09

2018/09/30 08:31 編集

nginxの設定(.conf内部)を見直して、proxy_read_timeout等の時間200とかに伸ばしてみました。追記したメモリ量だと、相対的に見て少ないでしょうか?まずは1アプリを試しにということで、1Gのプランにしています。 同じような事象の人たちの記事を見ると、fastCGIの設定を見直しているようなのですが、この環境においても有効なものでしょうか? インストールしてから、今の今までFastCGIについて触れていなかったのでnginxインストール時に組み込まれているものかもよく分からず・・・いくつも質問してしまいすみません。
scsi

2018/10/01 12:19

二重投稿しているようなので去りマース
guest

回答1

0

投稿から時間が経ち、もしかしたら既に解決されているかもしれませんが、
505のエラーが画面に出る場合、こちらは Nginx 側のエラーがブラウザ上で表示されている状況でしょうか。
気になったのは Nginx の設定ファイルです。 keepalive_timeout 5; とあり、クライアント側からリクエストが何もなければ、5秒でタイムアウトする設定です。 client timed out と出ているのは、その影響と思います。
デフォルト(何も指定しない)では75秒ですので、特に理由がないのであれば 5 から長い時間に指定し、様子を見られてはいかがでしょうか。

投稿2019/04/27 03:11

zembutsu

総合スコア1584

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問