LoginSignup
1
0

More than 1 year has passed since last update.

EC2でプロキシサーバーを利用する場合のプロキシ設定

Last updated at Posted at 2021-08-06

目的

AWS EC2から特定のプロキシサーバーをを経由してインターネット接続する場合のproxy設定を行う

背景

可用性が求められる環境においては、NATゲートウェイやVPCエンドポイントにインターネット接続を行うのが一般的であるが、開発環境等の可用性が求められない環境においては、コスト最適化のために低スペックのEC2によるプロキシサーバを立てて、インターネット接続させる場合がある。

その際に、設定が必要となった箇所と設定方法についてメモする。

EC2のproxy設定対象箇所

・OS(Linux)のシステム設定
・アプリのサービス
・CloudWatchAgent
・SSMAgent
・CodeDeployAgent

OSのシステム設定

sudo vi /etc/environment
http_proxy="http://{ProxyServerHost}:{Port}/"
HTTP_PROXY="http://{ProxyServerHost}:{Port}/"
https_proxy="http://{ProxyServerHost}:{Port}/"
HTTPS_PROXY="http://{ProxyServerHost}:{Port}/"
no_proxy="169.254.169.254"

アプリのサービス設定

今回SpringBootアプリをサービス登録しており、その設定ファイルに追加

sudo vi /opt/app/app.conf
export http_proxy="http://{ProxyServerHost}:{Port}/"
export HTTP_PROXY="http://{ProxyServerHost}:{Port}/"
export https_proxy="http://{ProxyServerHost}:{Port}/"
export HTTPS_PROXY="http://{ProxyServerHost}:{Port}/"
export no_proxy="169.254.169.254"

SSMAgentのproxy設定

sudo systemctl edit amazon-ssm-agent
[Service]
Environment="http_proxy=http://{ProxyServerHost}:{Port}"
Environment="https_proxy=http://{ProxyServerHost}:{Port}"
Environment="no_proxy=169.254.169.254"

以下のファイル名で保存
/etc/systemd/system/amazon-ssm-agent.service.d/amazon-ssm-agent.override.conf

sudo systemctl stop amazon-ssm-agent
sudo systemctl daemon-reload
sudo systemctl start amazon-ssm-agent

CodeDeployAgentのproxy設定

sudo vi /etc/codedeploy-agent/conf/codedeployagent.yml
:proxy_uri: 'http://{ProxyServerHost}:{Port}'

sudo service codedeploy-agent restart

CloudWatchAgentのproxy設定

sudo vi /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml

 [proxy]
    http_proxy = "http://{ProxyServerHost}:{Port}"
    https_proxy = "http://{ProxyServerHost}:{Port}"
    no_proxy = "169.254.169.254"

sudo systemctl stop amazon-cloudwatch-agent
sudo systemctl daemon-reload
sudo systemctl start amazon-cloudwatch-agent
1
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
1
0