LoginSignup
2
0

More than 3 years have passed since last update.

EC2をリバースプロキシサーバ化してElasticSearchServiceのAPIを外部から叩けるようにする

Posted at

経緯

Amazon Elasticsearch Serviceを使用してELasticSearchの検証環境を用意したが
Globalに公開できず検証しづらかったので、EC2をプロキシサーバにして外部からAPIを叩けるようにした。
セキュリティ的な問題はあるが検証環境であるということと自宅IPに絞ったので今回は甘めに

ざっくり構成

構成図.png

EC2を作成

EC2を作成し、PublicSubnetを紐づけます。

EC2用のセキュリティーグループを作成し、EC2に紐づける

今回EC2はHTTPでAPIを叩くようとSSHでリバースプロキシの設定をするために
インバウンドルールで80ポートと22ポートを解放するようにセキュリティーグループを設定します。

スクリーンショット 2020-07-10 19.06.01.png

ElasticSearchを作成

ElasticSearchを作成し、PrivateSubnetを紐づけます。

ElasticSearch用のセキュリティーグループを作成し、ElasticSearchに紐づける

ElasticSearchはEC2からのみのアクセスを受け付けたいので、
インバウンドルールにポート443 ソースにEC2のセキュリティーグループを設定します。
スクリーンショット 2020-07-10 19.16.55.png

EC2をリバースプロキシ化

今回はnginxで設定していきます。

sudo yum update -y
# nginxのインストール
sudo amazon-linux-extras install nginx1.12 -y
sudo vim /etc/nginx/nginx.conf

/etc/nginx/nginx.conf内に
locationの記述があると思うのでそちらにElasticSearchのVPCエンドポイントを記載します

/etc/nginx/nginx.conf
location / {
    proxy_pass ElasticSearchVPCエンドポイントを記載;
}
# nginxの起動
sudo systemctl start nginx
# EC2起動時に動くように
sudo systemctl enable nginx

EC2のpublic IPをブラウザ等で叩く

{
  "name" : "hogehoge",
  "cluster_name" : "hoge",
  "cluster_uuid" : "hogeid",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "oss",
    "build_type" : "tar",
    "build_hash" : "unknown",
    "build_date" : "2020-05-05T04:47:06.936807Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

成功🎉

2
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
2
0