0
0

More than 3 years have passed since last update.

AWSにデプロイしたら、ログイン機能が使えなかった話

Posted at

AWSにrailsアプリをデプロイ後に、サインアップしようとしたら、メールが送れない。
We're sorry, but something went wrong.が表示される。
こんな事象を治す過程を記します。

今回はログイン機能にDeviceを用いて実装しています。

環境
rails 6.0.3.2
ruby ruby 2.6.3p62
AWS amazonlinux
Nginx,unicornを使用

エラー

log/prodution.logに以下のようなエラーがでていました。

config/log/prodution.log
ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
 2:
 3: <p>You can confirm your account email through the link below:</p>
 4:
 5: <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

やったこと

本番環境でメール送信するため、
以下を参考に設定しました。
https://qiita.com/cigalecigales/items/16ce0a9a7e79b9c3974e#comments
今回は本番環境なので、

config/environments/production.rb
 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config/environmets/production.rb
config.action_mailer.default_url_options = { host: 'IPアドレスに変更'} 

AWSで設定したIPアドレスに変更しました。

app/views/devise/confirmation_instructions.html.erb
 5:<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>


 5: <p><%= link_to 'Confirm my account', user_confirmation_url(confirmation_token: @token) %></p>

エラーにPlease provide the :host parameter, set default_url_options[:host]
とあるので:hostが送られてきてないよということなので、
エラー文のでている5行目を変えました。

rails routesで〇〇_confirmationを調べて、変更しました。
今回は〇〇がuserになっています。

以下を参照しました。
http://renkaze.seesaa.net/article/374977746.html

おっと!!
こののままではダメで、
このcondig変更後に、
unicornを再起動させる必要があります。

ps aux | grep rails

で右側に出たunicornのプロセスIDのマスターになっているもの

kill プロセスID

unicorn起動

$ bundle exec unicorn_rails -c /var/www/rails/アプリ名/config/unicorn.conf.rb -D -E production

これをしてなかったが為に結構な時間を取られたのご注意ください。
初心者が忘れやすいミスなのかもですが、、

Deviceは便利ですが、エラーがでてしまうと
わりと困惑しますよね。

AWSのデプロイはこちらを参考にしました。
https://qiita.com/Yuki_Nagaoka/items/975b7598806d6ae0c0b2

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0