본문 바로가기
자격증

[리눅스마스터 1급] 15. 프록시 서비스 (Squid)

by LimSeongHyeon 2025. 5. 5.


porxy란?

프록시는 서버와 클라이언트 사이에서 중개해주는 대리자 역할을 한다. 즉, 클라이언트가 서버에 자신의 정보를 노출할 필요 없이 서버에 접근하게 된다. 

 

proxy 종류
종류 설명 예시
Forward Proxy 클라이언트 ↔ 프록시 ↔ 서버 / 주로 내부에서 외부로 사내 프록시, 학교 프록시
Reverse Proxy 클라이언트 ↔ 프록시 ↔ 내부 서버 / 주로 외부에서 내부로 Nginx, Apache Reverse Proxy
Transparent Proxy 클라이언트가 프록시 존재를 모름, 네트워크 차원에서 강제 적용 ISP, 회사 방화벽
SOCKS Proxy TCP 레벨에서 모든 트래픽을 중계 (HTTP뿐 아니라 SSH, FTP, 게임 등) SSH -D 옵션, Shadowsocks
  • 내부망에서 인터넷이 안되는데 curl로만 통신하고 싶다 → 프록시 설정
  • 웹 서버 부하 분산을 하고 싶다 → Nginx reverse proxy
  • 내 IP 숨기고 테스트하고 싶다 → SSH SOCKS Proxy, VPN
  • 서버 로그에 프록시 IP만 찍히고 실제 클라이언트 IP가 안 보인다 → X-Forwarded-For 헤더를 로그에 기록하도록 설정

squid 설치 및 설정

설치 및 실행
$ dnf install -y squid
$ systemctl start squid

 

설정 (squid.conf)

 

주요 설정

# 프록시가 요청을 수신할 포트 번호
http_port 3128

# 접근 제어 리스트 정의
acl localnet src 192.168.1.0/24
acl blocked_server dst 10.0.0.5
acl SSL_ports port 443
acl localdomain srcdomain .example.com
acl blocked_sites hackerdomain .cracker.com

# 접근 허용/거부 규칙
http_access allow localnet
http_access deny blocked_sites
http_access deny all

# 디스크 캐시 저장소 설정
cache_dir ufs /var/spool/squid 100 16 256

# 캐시 로그 파일 경로
cache_log /var/log/squid/cache.log

# 메모리 캐시 크기 (MB)
cache_mem 256 MB
항목 설명 예시 값 / 기본값
http_port 프록시가 요청을 수신할 포트 번호 3128 (기본값)
acl 접근 제어 리스트 정의 acl localnet src 192.168.1.0/24
acl blocked_server dst 10.0.0.5
acl SSL_ports port 443
acl localdomain srcdomain .example.com
acl blocked_sites dstdomain .facebook.com
http_access 접근 허용/거부 규칙 http_access allow localnet
cache_dir 디스크 캐시 저장소 설정 cache_dir ufs /var/spool/squid 100 16 256
cache_log 캐시 로그 파일 경로 cache_log /var/log/squid/cache.log
cache_mem 메모리 캐시 크기 (MB) 256 MB

 

 

부가적인 설정

항목 설명 예시 값 / 기본값
maximum_object_size 캐싱할 최대 객체 크기 (MB) 4 MB
minimum_object_size 캐싱할 최소 객체 크기 (KB) 0 KB
access_log 접근 로그 파일 경로 access_log /var/log/squid/access.log
pid_filename PID 파일 경로 pid_filename /var/run/squid.pid
cache_mgr 관리자 이메일 주소 cache_mgr admin@example.com
visible_hostname Squid 서버 이름 (로그, 에러 페이지에서 사용됨) visible_hostname proxy1
forwarded_for 클라이언트 IP 전달 여부 on / off / transparent
refresh_pattern 캐싱 주기 설정 refresh_pattern . 0 20% 4320
error_directory 사용자 정의 에러 페이지 경로 error_directory /usr/share/squid/errors/Korean
dns_nameservers 사용할 DNS 서버 직접 지정 dns_nameservers 8.8.8.8 8.8.4.4
request_header_access 특정 헤더 허용/차단 request_header_access X-Forwarded-For deny all

 

tip
$ man squid
...
       This   manual   page   only   lists   the   command  line  arguments.   For  details  on  how  to  configure  Squid  see  the  file
       /usr/share/doc/squid/squid.conf.documented, the Squid wiki FAQ and examples at http://wiki.squid-cache.org/ , or the  configuration
       manual on the Squid home page http://www.squid-cache.org/Doc/config/
...
man squid를 하면 /usr/share/doc/squid/squid.conf.documented이 경로를 볼드로 해놓고 디테일이나 어떻게 configure 하는지는 여기서 찾아보라고 한다.

 

 

$ cat /usr/share/doc/squid/squid.conf.documented

...
#  TAG: broken_vary_encoding
#	This option is not yet supported by Squid-3.
#Default:
# none
...
조회 해보면 이런식으로 TAG로 제공을 하고 경우에 따라 example을 제공하고 있는것이 보인다.

 

$ cat /usr/share/doc/squid/squid.conf.documented | grep "^#  TAG:" > squid_tags
$ cat squid_tags | grep port
#  TAG: wais_relay_port
#  TAG: on_unsupported_protocol
#  TAG: http_port
#  TAG: https_port
#  TAG: ftp_port
#  TAG: announce_port
#  TAG: snmp_port
#  TAG: icp_port
#  TAG: htcp_port
#  TAG: mcast_miss_port
이렇게 태그리스트를 만들어서 찾으면 좀 더 수월하게 찾을 수 있을 것 같다. 여기서 태그를 찾은 후 squid.conf.documentd에서 example까지 찾으면 squid 설정은 대부분 대응이 가능할 것이라고 본다.

문제

 

다음은 squid(프록시 서버)에 대한 설정이다. 조건에 맞게 알맞은 내용을 작성하세요.

① test_range src ②
http_access ③ test_range
http_access ④ ⑤

[조건]
192.168.10.0/24 네트워크 대역에 속한 호스트만 허가하고, 나머지 호스트는 모두 거부한다.
192.168.10.0/24 네트워크 대역은 "test_range"라는 별칭으로 관리한다.
더보기

1) acl

2) 192.168.10.0/24

3) allow

4) deny

5) all

 

다음은 squid(프록시 서버)에 대한 설정이다. 조건에 맞게 알맞은 내용을 작성하세요.

1) proxy 서버 포트를 8080으로 설정한다.
2) 192.168.10.0/24 대역의 호스트들의 별칭을 test_range로 설정한다.
3) test_range의 접근을 허가한다.
더보기

1) http_port 8080

2) acl testrange src 192.168.10.0/24

3) http_access allow test_range

 

 

다음은 squid(프록시 서버)에 대한 설정이다. 조건에 맞게 알맞은 내용을 작성하세요.

1) 10.24.5.0 대역의 호스트들의 별칭을 test_range로 설정한다.
2) test_range의 접근만 허용하고 나머지는 거부한다.
3) test_range의 대역을 C 클래스로 제한한다.
더보기

1) acl test_range src 10.24.5.0/24

2) http_access allow test_range

3) http_access deny all