質問編集履歴
1
エラーログ追加、ファイル追加、情報追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,12 +10,20 @@
|
|
10
10
|
|
11
11
|
メール内の認証リンクを押すと`https://api.my-service.net/api/v1/auth/confirmation?config=default&confirmation_token=hogefugabar`にリダイレクトされ、500エラーになります(URLが左記のものが残ったまま)。期待しているのはGET /api/v1/auth/confirmationで認証が処理された後、`https://my-service.net/account_confirmation_success=true`にリダイレクトされることです。
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
13
|
### エラーメッセージ
|
17
14
|
```error
|
18
15
|
500 Internal Server Error
|
16
|
+
|
17
|
+
Nginxコンテナのログ(CloudWatch)
|
18
|
+
|
19
|
+
# サインアップ
|
20
|
+
"POST /api/v1/auth/confirmation HTTP/1.1" 200 119 "https://www.my-service.net/"
|
21
|
+
|
22
|
+
# 認証リンク押下
|
23
|
+
"GET /api/v1/auth/confirmation?config=default&confirmation_token=ZhpLxqjmVbs4kgxS_QfH HTTP/1.1" 500 26 "-"
|
24
|
+
|
25
|
+
# 認証リンク押下と同時刻に出ているログ
|
26
|
+
[error] 14#14: *99 open() "/app/public/404.html" failed (2: No such file or directory), client: 10.0.1.23, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:///app/tmp/sockets/puma.sock/favicon.ico", host: "api.my-service.net", referrer: "https://api.my-service.net/api/v1/auth/confirmation?config=default&confirmation_token=ZhpLxqjmVbs4kgxS_QfH"
|
19
27
|
```
|
20
28
|
|
21
29
|
### 該当のソースコード
|
@@ -60,6 +68,64 @@
|
|
60
68
|
]
|
61
69
|
```
|
62
70
|
|
71
|
+
```
|
72
|
+
## Nginxの設定
|
73
|
+
|
74
|
+
# Pumaとの通信に Unixドメインソケット を利用
|
75
|
+
upstream api {
|
76
|
+
server unix:///app/tmp/sockets/puma.sock;
|
77
|
+
}
|
78
|
+
|
79
|
+
server {
|
80
|
+
listen 80;
|
81
|
+
server_name localhost;
|
82
|
+
|
83
|
+
# ログ出力先
|
84
|
+
access_log /var/log/nginx/access.log;
|
85
|
+
error_log /var/log/nginx/error.log;
|
86
|
+
|
87
|
+
# 静的ファイルのルート(Railsの /public を参照)
|
88
|
+
root /app/public;
|
89
|
+
|
90
|
+
# クライアントがアップロード可能な最大リクエストサイズ(m = MB)
|
91
|
+
client_max_body_size 100m;
|
92
|
+
|
93
|
+
keepalive_timeout 5;
|
94
|
+
|
95
|
+
# ALBからのヘルスチェックエンドポイント
|
96
|
+
location = /healthcheck {
|
97
|
+
access_log off;
|
98
|
+
return 200 "OK";
|
99
|
+
add_header Content-Type text/plain;
|
100
|
+
}
|
101
|
+
|
102
|
+
# エラーページ指定
|
103
|
+
error_page 404 /404.html;
|
104
|
+
error_page 502 503 504 505 /500.html;
|
105
|
+
|
106
|
+
# エラーページへの直接アクセスをブロック
|
107
|
+
location = /404.html {
|
108
|
+
internal;
|
109
|
+
}
|
110
|
+
|
111
|
+
location = /500.html {
|
112
|
+
internal;
|
113
|
+
}
|
114
|
+
|
115
|
+
# リクエストファイル($uri)が存在すれば返し、なければRailsへルーティング
|
116
|
+
try_files $uri @api;
|
117
|
+
|
118
|
+
# リバースプロキシ設定
|
119
|
+
location @api {
|
120
|
+
proxy_pass http://api;
|
121
|
+
proxy_set_header Host $host;
|
122
|
+
proxy_set_header X-Real-IP $remote_addr;
|
123
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
124
|
+
proxy_intercept_errors on;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
```
|
128
|
+
|
63
129
|
### 試したこと・調べたこと
|
64
130
|
- [x] teratailやGoogle等で検索した
|
65
131
|
- [x] ソースコードを自分なりに変更した
|
@@ -74,3 +140,12 @@
|
|
74
140
|
Ruby: 3.3.7 Rails: 7.2.2.1
|
75
141
|
RailsはAPIモード
|
76
142
|
検証していませんが、同じ理由で本番でパスワードリセットリンクを踏んでも失敗すると想像しています
|
143
|
+
|
144
|
+
追記:
|
145
|
+
|
146
|
+
開発:Next.js, Nginx, Rails, Postgresをコンテナ化して疎通
|
147
|
+
本番:Vercel(Next.js), Route53 → ALB → ECS Fargate(Nginx/Rails)→ RDS
|
148
|
+
|
149
|
+
環境は上記です。S3はまだ未設置のためALBのログなし、Railsログはマイグレーションや起動成功したことのみログに出ています。クライアントからRailsへの他リクエストやRDSとの疎通は問題ありません。Nginxのエラーログはこのタイミングで初めて出ましたが今回のエラーと関係あるかは不明。
|
150
|
+
|
151
|
+
本番用の環境変数はタスク定義で渡しています。何度も確認したので設定値に誤りはないと思います。
|