やりたいこと
- infratasterでhttp://endpoint-xxx.reviewapps.speee.jp のroutingがテストできる
1pomo 10:20 - 10:45
- テストで動くことを確認する
- テスト用データを投入できるようにする。
- テスト用データは作り直しができるようにする
docker exec revieee_nginx_container /usr/local/nginx/sbin/nginx -s reload
とりあえず、http://endpoint-1.reviewapps.speee.jp にアクセスしたら、 http://127.0.0.1:3000 が返ってくるところまでやった。 IPは127.0.0.1、PORTは3000で良さそう。
次は、proxy_passに http://127.0.0.1:3000 が入ってるか確認したい。 とはいえ、proxy_passを入れないときに出てくるエラーを見ておく。
revieee_nginx_container | 2017/07/10 01:26:36 [error] 18#0: *6 invalid URL prefix in "", client: 172.21.0.3, server: ~^endpoint-(?<endpoint_id>\d+)\.reviewapps\.speee\.jp$, request: "GET / HTTP/1.1", host: "endpoint-1.reviewapps.speee.jp"
ということで、proxy_passに何も入ってなかったのかと思い、ちょっといじってみる。 https://github.com/speee/webapp-revieee/commit/d5ce8f9ffb7feeea4745f4b4771af05cb32860d0
revieee_nginx_container | 2017/07/10 01:36:36 [error] 28#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 172.21.0.3, server: ~^endpoint-(?<endpoint_id>\d+)\.reviewapps\.speee\.jp$, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "endpoint-1.reviewapps.speee.jp"
エラーが変わった。http://127.0.0.1:3000 に接続できなかったよ!ってエラーっぽい。 なので、テスト用の環境があると良さそう… 一旦、同一nginx内のリクエストに飛ばし直して、今存在しているコードも少し手をいれておく。
% docker exec -it revieee_nginx_container /bin/bash [10:43:18] root@ebf6209b9bf2:/# curl http://127.0.0.1 This is test for ngx_mruby hoge
テストコードを作って動作を確認。どうやら大丈夫そうだ。 次は、mysql serverに入って、データをちょっといじっておく。
% mysql -u root --port 33306 -h 127.0.0.1 mysql> use revieee_development; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from endpoints; +------+-----------+------+---------+ | id | ip | port | task_id | +------+-----------+------+---------+ | 1 | 127.0.0.1 | 3000 | 1 | +------+-----------+------+---------+ 1 row in set (0.00 sec) mysql> update endpoints set port=80 where id=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
で、もう一度やってみる。
revieee_nginx_container | 2017/07/10 01:49:46 [error] 57#0: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 172.21.0.3, server: ~^endpoint-(?<endpoint_id>\d+)\.reviewapps\.speee\.jp$, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "endpoint-1.reviewapps.speee.jp"
2pomo 10:50 - 11:15
またportが変わってない。そうか nginxのメモリにキャッシュされてるんだ。 キャッシュクリアしないと。
http://qiita.com/zaru/items/c41072e29b9550c2e6a8
↑を読んでみるが、僕たちの実装と結構大きく違う… ふーむ… nginxのキャッシュ周りは後で勉強しないと。 実践 nginxが、今ならちゃんと読みたいと思えるはず。
とりあえず今は、cache clear用のコードを書こう。
% curl -H "Host: endpoint-1.reviewapps.speee.jp" http://127.0.0.1/revieee/clear <html> <head><title>502 Bad Gateway</title></head> <body bgcolor="white"> <center><h1>502 Bad Gateway</h1></center> <hr><center>nginx/1.13.0</center> </body> </html>
clearにつかったコードはこちら https://github.com/speee/webapp-revieee/pull/73/commits/205c1e956df7d33e56bf4ecf50e1743011cbd962
がっつり重複しているので、いい感じに整理したい。
3pomo 11:20 - 11:45
挙動を整理する。
- キャッシュは消せたのか?
- 消せてたら、502問題だけどうにかする
- 消せてなかったら、何がいけないのか調査する
% curl -H "Host: endpoint-1.reviewapps.speee.jp" http://127.0.0.1 [11:25:18] <html> <head><title>502 Bad Gateway</title></head> <body bgcolor="white"> <center><h1>502 Bad Gateway</h1></center> <hr><center>nginx/1.11.13</center> </body> </html>
revieee_nginx_container | 2017/07/10 02:25:53 [error] 99#0: *4479 upstream prematurely closed connection while reading response header from upstream, client: 172.21.0.3, server: ~^endpoint-(?<endpoint_id>\d+)\.reviewapps\.speee\.jp$, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:80/", host: "endpoint-1.reviewapps.speee.jp"
ふーむ…とりあえず、今日はここまで。 テストデータ作成用のscriptは用意したい。