前提
現在RailsでWebアプリケーションを作成しております。
以下、2つのgemを利用しアプリケーションでは、
すでにGoogleアカウントを利用したSNSログイン昨日は実装できております。
'omniauth'、'omniauth-google-oauth2'
実現したいこと
Twitterのアカウントを利用しWebアプリケーションにログインするSNS機能実装したいです。
また、ローカルで実行できていたので、本番環境にデプロイし、
アプリケーションの画面上からtwitterでログインを実施したところ、「Internal Server Error」と表示されてしました。
Unicoenのエラーメッセージは以下のようになっておりました。
発生している問題・エラーメッセージ
Started GET "/users/auth/twitter" for 126.55.113.184 at 2020-05-05 08:51:38 +0900 FATAL -- : [db9e50a9-75a9-4af7-bc1f-6ad52b99a580] OAuth::Unauthorized (403 Forbidden): FATAL -- : [db9e50a9-75a9-4af7-bc1f-6ad52b99a580] FATAL -- : [db9e50a9-75a9-4af7-bc1f-6ad52b99a580] oauth (0.5.4) lib/oauth/consumer.rb:236:in `token_request' oauth (0.5.4) lib/oauth/consumer.rb:155:in `get_request_token' omniauth-oauth (1.1.0) lib/omniauth/strategies/oauth.rb:28:in `request_phase' omniauth-twitter (1.4.0) lib/omniauth/strategies/twitter.rb:61:in `request_phase' omniauth (1.9.1) lib/omniauth/strategy.rb:226:in `request_call' omniauth (1.9.1) lib/omniauth/strategy.rb:188:in `call!' omniauth (1.9.1) lib/omniauth/strategy.rb:169:in `call' omniauth (1.9.1) lib/omniauth/strategy.rb:192:in `call!' omniauth (1.9.1) lib/omniauth/strategy.rb:169:in `call' warden (1.2.8) lib/warden/manager.rb:36:in `block in call' warden (1.2.8) lib/warden/manager.rb:34:in `catch' warden (1.2.8) lib/warden/manager.rb:34:in `call' rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call' rack (2.2.2) lib/rack/etag.rb:27:in `call' rack (2.2.2) lib/rack/conditional_get.rb:27:in `call' rack (2.2.2) lib/rack/head.rb:12:in `call' actionpack (5.2.3) lib/action_dispatch/http/content_security_policy.rb:18:in `call' rack (2.2.2) lib/rack/session/abstract/id.rb:266:in `context' rack (2.2.2) lib/rack/session/abstract/id.rb:260:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/cookies.rb:670:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks' actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.3) lib/rails/rack/logger.rb:26:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.2.2) lib/rack/method_override.rb:24:in `call' rack (2.2.2) lib/rack/runtime.rb:22:in `call' activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call' rack (2.2.2) lib/rack/sendfile.rb:110:in `call' railties (5.2.3) lib/rails/engine.rb:524:in `call' rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call' rack (2.2.2) lib/rack/common_logger.rb:38:in `call' rack (2.2.2) lib/rack/chunked.rb:98:in `call' rack (2.2.2) lib/rack/content_length.rb:17:in `call' unicorn (5.5.3) lib/unicorn/http_server.rb:605:in `process_client' unicorn (5.5.3) lib/unicorn/http_server.rb:700:in `worker_loop' unicorn (5.5.3) lib/unicorn/http_server.rb:548:in `spawn_missing_workers' unicorn (5.5.3) lib/unicorn/http_server.rb:144:in `start' unicorn (5.5.3) bin/unicorn:128:in `<top (required)>' /var/www/OWARAIMOVE/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `load' /var/www/OWARAIMOVE/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `<top (required)>' bundler (2.1.4) lib/bundler/cli/exec.rb:63:in `load' bundler (2.1.4) lib/bundler/cli/exec.rb:63:in `kernel_load' bundler (2.1.4) lib/bundler/cli/exec.rb:28:in `run' bundler (2.1.4) lib/bundler/cli.rb:476:in `exec' bundler (2.1.4) lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' bundler (2.1.4) lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' bundler (2.1.4) lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch' bundler (2.1.4) lib/bundler/cli.rb:30:in `dispatch' bundler (2.1.4) lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start' bundler (2.1.4) lib/bundler/cli.rb:24:in `start' bundler (2.1.4) exe/bundle:46:in `block in <top (required)>' bundler (2.1.4) lib/bundler/friendly_errors.rb:123:in `with_friendly_errors' bundler (2.1.4) exe/bundle:34:in `<top (required)>' /usr/local/rbenv/versions/2.6.3/bin/bundle:23:in `load' /usr/local/rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Started GET "/500.png" for 126.55.113.184 at 2020-05-05 08:51:38 +0900 FATAL -- : [6b0711b8-6f21-4cd0-ba7d-231e36b7cf2d] FATAL -- : [6b0711b8-6f21-4cd0-ba7d-231e36b7cf2d] ActionController::RoutingError (No route matches [GET] "/500.png"): FATAL -- : [6b0711b8-6f21-4cd0-ba7d-231e36b7cf2d] FATAL -- : [6b0711b8-6f21-4cd0-ba7d-231e36b7cf2d] actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
nginx
1upstream unicorn { 2 server unix:/var/www/OWARAIMOVE/shared/tmp/sockets/unicorn.sock; 3} 4server { 5 listen 80; 6 server_name www.owaraimove.net; 7 8 root /var/www/OWARAIMOVE/shared/public; 9 access_log /var/log/nginx/OWARAIMOVE_access.log; 10 error_log /var/log/nginx/OWARAIMOVE_error.log; 11 location ~ ^/assets/ { 12 } 13 location / { 14 proxy_set_header X-Real-IP $remote_addr; 15 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16 proxy_set_header Host $http_host; 17 proxy_pass http://unicorn; 18 } 19 }
Unicorn
1$worker = 2 2$timeout = 30 3$app_dir = "/var/www/OWARAIMOVE/current" 4$listen = File.expand_path 'tmp/sockets/unicorn.sock', $app_dir 5$pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir 6$std_log = File.expand_path 'log/unicorn.log', $app_dir 7worker_processes $worker 8working_directory $app_dir 9stderr_path $std_log 10stdout_path $std_log 11timeout $timeout 12listen $listen 13pid $pid 14preload_app true 15before_fork do |server, worker| 16 defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 17 old_pid = "#{server.config[:pid]}.oldbin" 18 if old_pid != server.pid 19 begin 20 Process.kill "QUIT", File.read(old_pid).to_i 21 rescue Errno::ENOENT, Errno::ESRCH 22 end 23 end 24end 25after_fork do |server, worker| 26 defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
試したこと
エラーメッセージの内容の(OAuth::Unauthorized (403 Forbidden):)について調査したところ、
同様の事象が起きていることがあったので参考に
Twitter DeveloperのコールバックURLを見直しました。
こちらは初めから設定していたのでこちらでは解決に至りませんでした。
前提条件でも記載がありますが、ローカルでは正常に動いているので、
Unicorn、nginxの設定の問題だと思っております。
こちら設定をどのように変更すれば正常に動作するかお教え願えますでしょうか。
参考情報
https://qiita.com/mh4gf/items/41d2c868317edea5045b
補足情報(FW/ツールのバージョンなど)
Ruby 2.6.3
Rails 5.2.3
unicorn-5.5.3
nginx/1.16.1
あなたの回答
tips
プレビュー