반응형
 
 
HTTP Proxy를 이용한 사내 방화벽/보안장비(Outbound 액세스 제한)로 인한 API 접속 문제를 해결하는 방법입니다.
 
1. Squid 서버 설치
 
GCP에 VM 작은 걸 하나 만드시고... (Static IP 부여)
CentOS 같은 경우는 그냥 다음과 같이 하면 됩니다. 
Ubuntu 계열도 어렵진 않을 듯 합니다.
 
yum install squid
 
2. Squid 서버 설정
 
vi /etc/squid/squid.conf
 
다음과 같이해서 모든 외부서버로 접속을 가능하게 합니다. (설정 파일을 완전히 교체)
(Google API IP가 계속 변경되므로 DNS를 이용한 Outbound 설정 필요)
설정에서 allowed_ip를 변경하여 허용되는 소스 IP를 추가할 수 있습니다.
SSL_ports에는 SSL로 사용할 포트, Safe_ports에는 일반 허용 가능한 포트를 지정합니다.
http_access allow CONNECT 에 SSL로 접근 가능한 조건을 선택합니다.
http_access allow 에 Non-SSL로 접근 가능한 조건을 선택합니다.
 
# For Google Cloud
acl allowed_ip src 10.146.0.2/32 1.240.103.160/32 104.198.121.215/32
acl CONNECT method CONNECT
acl google_apis dstdomain .googleapis.com .google.com
acl SSL_ports port 443
acl Safe_ports port 80
http_access allow CONNECT allowed_ip google_apis SSL_Ports
http_access allow allowed_ip google_apis Safe_Ports
http_access deny all
http_port 0.0.0.0:8080
 
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
 
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
 
#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
 
3. VM의 방화벽 설정
 
우선 VM 내부 파이어월을 열어 주고 (방화벽이 있다면)
 
sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp; sudo firewall-cmd --reload
 
VPC 설정에서 8080 포트를 역시 열어 줍니다. 아래는 각각 VPC Firewall과 VM Network의 설정입니다.
단, 이 때 외부에서 접속 가능한 IP를 반드시 PC가 있는 사무실이나 서버가 있는 IDC로 제한을 하셔야 합니다.
 
 
4. API 호출 클라이언트에서 사용 방법
 
다음과 같이 Proxy 서버를 환경변수에 지정합니다. profile 스크립트에 넣어도 좋겠죠
export http_proxy=http://<squid vm ip>:8080
export https_proxy=http://<squid vm ip>:8080
 
==> 제외하고 싶은 주소가 있다면 다음과 같이 설정합니다.
export no_proxy="ecar-web01,ecar-iot01,172.20.90.60,172.20.90.62"
 
5. Java에서는
 
다음과 같이 옵션을 지정합니다.
java -Dhttps.proxyHost=35.187.200.95 -Dhttps.proxyPort=8080
 
 
그리고 나서 API 호출하시면 Squid HTTP Proxy를 통해서 실행이 됩니다.
내부 방화벽이나 보안장비에서 squid vm ip를 제외하시면 됩니다.
Posted by Hey Jerry
,