0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

EC2でフロント構築 500番エラー 

Posted at

環境

  • Java: 21.0.6 (2025-01-21 LTS)
    • Java(TM) SE Runtime Environment (build 21.0.6+8-LTS-188)
    • Java HotSpot(TM) 64-Bit Server VM (build 21.0.6+8-LTS-188, mixed mode, sharing)
  • Node.js: v22.13.1
  • MySQL: 8.x 系

1. エラー内容 

500.png

  • ブラウザでアクセスをしたらこんなエラーが
  • Jarファイルが起動されていなかったので実行する。

2. DBの作成(初歩的すぎた。。。)

19:48.731Z ERROR 4996 --- [todo-backend] [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Access denied for user 'root'@'localhost
  • 認証がうまくできていなかったのでrootユーザにapplication.propertiesで設定したユーザ情報を与える
35:13.595Z ERROR 5326 --- [todo-backend] [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown database 'todo'
  • DBがないだと...?
  • GPTに聞いたらDBを自分で作れと言われたので自分で作成し、実行
~/todo/backend/target$ ps aux | grep java
ubuntu      5418  5.1 20.7 2368084 203712 pts/0  Sl   16:54   0:11 java -jar todo-backend-0.0.1-SNAPSHOT.jar
  • プロセスが存在することを確認
  • しかし、Curlを叩いても500番エラーであるのでNginxの再設定を行う

3. Nginxの設定変更

:/etc/nginx/sites-available$ ls -l /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx 1 root root 34 Mar 24 17:46 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 35 Mar 25 10:14 todo-app -> /etc/nginx/sites-available/todo-app
  • 設定ファイルが競合している?とりあえずdefaultを削除
  • しかし、治らず。。。
ubuntu@ip-:/etc/nginx/sites-available$ sudo tail -n 50 /var/log/nginx/error.log
  • ログを吐き出すと、Permission denied と権限不足
sudo chmod -R o+rX /home/ubuntu/todo/frontend/dist
sudo chmod o+x /home/ubuntu
sudo chmod o+x /home/ubuntu/todo
sudo chmod o+x /home/ubuntu/todo/frontend
  • -R: 再帰的に
  • o+rX: 「他人(others)」にも読み取り(r)・実行権(X=ディレクトリ&実行可能なファイルのみ)を付ける

エラー解消

スクリーンショット 2025-03-25 180611.png

  • 無事表示される。
  • 権限エラーとDB作成という初歩的なエラーでしたね。
    • ログを出力して原因特定することが重要でした。
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?