Squidを利用してプロキシサーバー構築してみた

プロキシ設定の挙動を確認するために、Squidを利用して簡単なプロキシサーバーを構築してみました。

 

今回の記事は、AWS上に作成した"Amazon Linux 2023"のサーバーへ"Squid"を導入し、プライベートサブネット上の"Windows Server"からプロキシ経由でインターネット通信できるかを確認した際の作業メモです。

 

本格的な商用利用を前提とした構成ではなく、とりあえず"プロキシ経由で通信できるか"を確認するための最小構成として試しています。

 

プロキシ設定の動作確認をしたい場合や、検証用に簡単なプロキシサーバーを立ててみたい場合の参考になればと思います。

 

 

■Squidとは

Squidは、HTTPやHTTPSなどの通信を中継するための代表的なプロキシサーバーソフトウェアです。

 

Linuxサーバーへ比較的簡単に導入でき、アクセス制御やログ確認も行いやすいため、今回のような検証用途でも扱いやすいのが特徴です。

 

今回は、Windows Serverからの通信を一度Squidサーバーで受け、その先のインターネットへ中継できるかを確認することを目的としました。

 

Squidについて詳しく知りたい方はこちら

 

 

■squid.confの見方

Squid導入の際に、ほぼ“Squidの本体”とも呼べる"squid.conf"の見方に詰まったので、事前に説明します。

 

Squidの設定ファイル/etc/squid/squid.confでは、主に以下の3点を設定します。
 

  • どの送信元を許可するか
  • どの通信を許可または拒否するか
  • どのポートで待ち受けるか

 

【デフォルトのsquid.conf】

#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8             # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10          # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16         # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12          # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16         # RFC 1918 local private network (LAN)
acl localnet src fc00::/7               # RFC 4193 local private network range
acl localnet src fe80::/10              # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# This default configuration only allows localhost requests because a more
# permissive Squid installation could introduce new attack vectors into the
# network by proxying external TCP connections to unprotected services.
http_access allow localhost

# The two deny rules below are unnecessary in this default configuration
# because they are followed by a "deny all" rule. However, they may become
# critically important when you start allowing external requests below them.

# Protect web applications running on the same server as Squid. They often
# assume that only local users can access them at "localhost" ports.
http_access deny to_localhost

# Protect cloud servers that provide local users with sensitive info about
# their server via certain well-known link-local (a.k.a. APIPA) addresses.
http_access deny to_linklocal

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# For example, to allow access from your local networks, you may uncomment the
# following rule (and/or add rules that match your definition of "local"):
# http_access allow localnet

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# 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 -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

 

設定ファイルを見ると項目が多く少し難しそうに見えますが、基本的にはaclで条件を定義し、http_accessでその条件に対する許可・拒否を記述する形になっています。

 

なので、Squidの設定は、

 

「どこから来た通信を、どこまで許可するか」を順番に評価している

 

と考えると理解しやすいです。

 

たとえば以下のような設定は、HTTPSの標準ポートである443をSSL用ポートとして定義しています。

acl SSL_ports port 443

 

また、以下は安全とみなす接続先ポートを定義しています。

acl Safe_ports port 80
acl Safe_ports port 443

 

続くhttp_access deny !Safe_portsは、Safe_portsに含まれない宛先ポートへのアクセスを拒否する設定です。

 

このように、aclhttp_accessを組み合わせてアクセス制御を実現します。

 

なお、初期状態の設定ではhttp_access allow localhostのみが有効で、ローカルホストからのアクセスしか許可されていません。

 

そのため、別サーバーからプロキシとして利用したい場合は、接続元サーバーのIPアドレスを明示的に許可する設定を追加する必要があります。

 

 

■準備

今回の検証では、以下の2台のサーバーを利用しました。

 

  • Amazon Linux 2023
    ⇒ Squid を導入するプロキシサーバー
  • Windows Server 2025
    ⇒ プロキシ経由でインターネット接続を試すクライアントサーバー

 

あわせて、両サーバーへログインできること、またネットワーク的にWindows ServerからSquidサーバーへ到達できることを前提とします。

 

今回の構成では、Squidサーバーをパブリックサブネット、Windows Serverをプライベートサブネットに配置して検証しました。

 

 

■手順

まずは、Amazon Linux 2023側でSquidをインストールし、サービスを起動します。

 

インストール自体はそれほど難しくなく、dnf installで導入後、設定ファイルを編集してサービスを開始すれば、基本的なプロキシサーバーとして利用できます。

 

sudo dnf install -y squid
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
sudo vi /etc/squid/squid.conf
sudo systemctl enable squid
sudo systemctl start squid
sudo systemctl status squid

 

squid.confには、接続元となる Windows ServerのIPアドレスを許可する設定を追加しました。

 

初期設定のままではlocalhostからのアクセスしか通らないため、クライアントサーバーのIPをACLとして定義し、そのACLをhttp_access allowで許可しています。

 
以下をsquid.confの8行目あたりに、

acl localnet src {接続元サーバーIP}/32

 

以下をsquid.confの60行目あたりに追記します。

http_access allow localnet
http_access deny all

 

【実行結果】

[ec2-user@ip-10-0-1-158 ~]$ sudo dnf install -y squid
Last metadata expiration check: 0:05:40 ago on Sat Apr  4 03:56:06 2026.
Dependencies resolved.
==========================================================================================================================================================
 Package                               Architecture               Version                                           Repository                       Size 
==========================================================================================================================================================
Installing:
 squid                                 x86_64                     7:6.13-1.amzn2023.0.3                             amazonlinux                     3.5 M
Installing dependencies:
 httpd-filesystem                      noarch                     2.4.66-1.amzn2023.0.1                             amazonlinux                      13 k 
 libecap                               x86_64                     1.0.1-10.amzn2023                                 amazonlinux                      26 k 
 libtool-ltdl                          x86_64                     2.4.7-1.amzn2023.0.3                              amazonlinux                      38 k 
 perl-B                                x86_64                     1.80-477.amzn2023.0.7                             amazonlinux                     177 k 
 perl-DBI                              x86_64                     1.643-7.amzn2023.0.3                              amazonlinux                     700 k 
 perl-Data-Dumper                      x86_64                     2.191-522.amzn2023.0.1                            amazonlinux                      57 k 
 perl-Digest                           noarch                     1.20-1.amzn2023.0.2                               amazonlinux                      26 k 
 perl-Digest-MD5                       x86_64                     2.59-521.amzn2023.0.1                             amazonlinux                      37 k 
 perl-Digest-SHA                       x86_64                     1:6.04-522.amzn2023.0.1                           amazonlinux                      63 k 
 perl-English                          noarch                     1.11-477.amzn2023.0.7                             amazonlinux                      13 k 
 perl-FileHandle                       noarch                     2.03-477.amzn2023.0.7                             amazonlinux                      15 k 
 perl-IO-Socket-IP                     noarch                     0.41-3.amzn2023.0.2                               amazonlinux                      42 k 
 perl-Math-BigInt                      noarch                     1:1.9998.39-2.amzn2023.0.2                        amazonlinux                     202 k 
 perl-Math-BigRat                      noarch                     0.2624-500.amzn2023.0.2                           amazonlinux                      42 k 
 perl-Math-Complex                     noarch                     1.59-477.amzn2023.0.7                             amazonlinux                      46 k 
 perl-URI                              noarch                     5.09-1.amzn2023.0.2                               amazonlinux                     108 k 
 perl-libnet                           noarch                     3.13-2.amzn2023.0.2                               amazonlinux                     126 k 

Transaction Summary
==========================================================================================================================================================
Install  18 Packages

Total download size: 5.2 M
Installed size: 16 M
Downloading Packages:
(1/18): libtool-ltdl-2.4.7-1.amzn2023.0.3.x86_64.rpm                                                                      1.0 MB/s |  38 kB     00:00     
(2/18): httpd-filesystem-2.4.66-1.amzn2023.0.1.noarch.rpm                                                                 310 kB/s |  13 kB     00:00     
(3/18): libecap-1.0.1-10.amzn2023.x86_64.rpm                                                                              585 kB/s |  26 kB     00:00     
(4/18): perl-B-1.80-477.amzn2023.0.7.x86_64.rpm                                                                           5.5 MB/s | 177 kB     00:00     
(5/18): perl-Data-Dumper-2.191-522.amzn2023.0.1.x86_64.rpm                                                                2.0 MB/s |  57 kB     00:00     
(6/18): perl-DBI-1.643-7.amzn2023.0.3.x86_64.rpm                                                                           18 MB/s | 700 kB     00:00     
(7/18): perl-Digest-MD5-2.59-521.amzn2023.0.1.x86_64.rpm                                                                  1.5 MB/s |  37 kB     00:00     
(8/18): perl-Digest-1.20-1.amzn2023.0.2.noarch.rpm                                                                        822 kB/s |  26 kB     00:00     
(9/18): perl-Digest-SHA-6.04-522.amzn2023.0.1.x86_64.rpm                                                                  2.5 MB/s |  63 kB     00:00     
(10/18): perl-English-1.11-477.amzn2023.0.7.noarch.rpm                                                                    504 kB/s |  13 kB     00:00     
(11/18): perl-FileHandle-2.03-477.amzn2023.0.7.noarch.rpm                                                                 580 kB/s |  15 kB     00:00     
(12/18): perl-IO-Socket-IP-0.41-3.amzn2023.0.2.noarch.rpm                                                                 1.6 MB/s |  42 kB     00:00     
(13/18): perl-Math-BigInt-1.9998.39-2.amzn2023.0.2.noarch.rpm                                                             7.2 MB/s | 202 kB     00:00     
(14/18): perl-Math-BigRat-0.2624-500.amzn2023.0.2.noarch.rpm                                                              1.5 MB/s |  42 kB     00:00     
(15/18): perl-Math-Complex-1.59-477.amzn2023.0.7.noarch.rpm                                                               1.6 MB/s |  46 kB     00:00     
(16/18): perl-URI-5.09-1.amzn2023.0.2.noarch.rpm                                                                          4.2 MB/s | 108 kB     00:00     
(17/18): perl-libnet-3.13-2.amzn2023.0.2.noarch.rpm                                                                       4.8 MB/s | 126 kB     00:00     
(18/18): squid-6.13-1.amzn2023.0.3.x86_64.rpm                                                                              28 MB/s | 3.5 MB     00:00     
----------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                      16 MB/s | 5.2 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: squid-7:6.13-1.amzn2023.0.3.x86_64                                                                                               1/1 
  Preparing        :                                                                                                                                  1/1 
  Installing       : perl-FileHandle-2.03-477.amzn2023.0.7.noarch                                                                                    1/18 
  Installing       : perl-Math-Complex-1.59-477.amzn2023.0.7.noarch                                                                                  2/18 
  Installing       : perl-Math-BigRat-0.2624-500.amzn2023.0.2.noarch                                                                                 3/18 
  Installing       : perl-Math-BigInt-1:1.9998.39-2.amzn2023.0.2.noarch                                                                              4/18 
  Installing       : perl-Digest-1.20-1.amzn2023.0.2.noarch                                                                                          5/18 
  Installing       : perl-Digest-MD5-2.59-521.amzn2023.0.1.x86_64                                                                                    6/18 
  Installing       : perl-Digest-SHA-1:6.04-522.amzn2023.0.1.x86_64                                                                                  7/18 
  Installing       : perl-Data-Dumper-2.191-522.amzn2023.0.1.x86_64                                                                                  8/18 
  Installing       : perl-B-1.80-477.amzn2023.0.7.x86_64                                                                                             9/18 
  Installing       : perl-DBI-1.643-7.amzn2023.0.3.x86_64                                                                                           10/18 
  Installing       : perl-IO-Socket-IP-0.41-3.amzn2023.0.2.noarch                                                                                   11/18 
  Installing       : perl-libnet-3.13-2.amzn2023.0.2.noarch                                                                                         12/18 
  Installing       : perl-URI-5.09-1.amzn2023.0.2.noarch                                                                                            13/18 
  Installing       : perl-English-1.11-477.amzn2023.0.7.noarch                                                                                      14/18 
  Installing       : libtool-ltdl-2.4.7-1.amzn2023.0.3.x86_64                                                                                       15/18 
  Installing       : libecap-1.0.1-10.amzn2023.x86_64                                                                                               16/18 
  Running scriptlet: httpd-filesystem-2.4.66-1.amzn2023.0.1.noarch                                                                                  17/18 
  Installing       : httpd-filesystem-2.4.66-1.amzn2023.0.1.noarch                                                                                  17/18 
  Running scriptlet: squid-7:6.13-1.amzn2023.0.3.x86_64                                                                                             18/18 
  Installing       : squid-7:6.13-1.amzn2023.0.3.x86_64                                                                                             18/18 
  Running scriptlet: squid-7:6.13-1.amzn2023.0.3.x86_64                                                                                             18/18 
  Verifying        : httpd-filesystem-2.4.66-1.amzn2023.0.1.noarch                                                                                   1/18 
  Verifying        : libecap-1.0.1-10.amzn2023.x86_64                                                                                                2/18 
  Verifying        : libtool-ltdl-2.4.7-1.amzn2023.0.3.x86_64                                                                                        3/18 
  Verifying        : perl-B-1.80-477.amzn2023.0.7.x86_64                                                                                             4/18 
  Verifying        : perl-DBI-1.643-7.amzn2023.0.3.x86_64                                                                                            5/18 
  Verifying        : perl-Data-Dumper-2.191-522.amzn2023.0.1.x86_64                                                                                  6/18 
  Verifying        : perl-Digest-1.20-1.amzn2023.0.2.noarch                                                                                          7/18 
  Verifying        : perl-Digest-MD5-2.59-521.amzn2023.0.1.x86_64                                                                                    8/18 
  Verifying        : perl-Digest-SHA-1:6.04-522.amzn2023.0.1.x86_64                                                                                  9/18 
  Verifying        : perl-English-1.11-477.amzn2023.0.7.noarch                                                                                      10/18 
  Verifying        : perl-FileHandle-2.03-477.amzn2023.0.7.noarch                                                                                   11/18 
  Verifying        : perl-IO-Socket-IP-0.41-3.amzn2023.0.2.noarch                                                                                   12/18 
  Verifying        : perl-Math-BigInt-1:1.9998.39-2.amzn2023.0.2.noarch                                                                             13/18 
Installed:
  httpd-filesystem-2.4.66-1.amzn2023.0.1.noarch        libecap-1.0.1-10.amzn2023.x86_64                  libtool-ltdl-2.4.7-1.amzn2023.0.3.x86_64
  perl-B-1.80-477.amzn2023.0.7.x86_64                  perl-DBI-1.643-7.amzn2023.0.3.x86_64              perl-Data-Dumper-2.191-522.amzn2023.0.1.x86_64
  perl-Digest-1.20-1.amzn2023.0.2.noarch               perl-Digest-MD5-2.59-521.amzn2023.0.1.x86_64      perl-Digest-SHA-1:6.04-522.amzn2023.0.1.x86_64
  perl-English-1.11-477.amzn2023.0.7.noarch            perl-FileHandle-2.03-477.amzn2023.0.7.noarch      perl-IO-Socket-IP-0.41-3.amzn2023.0.2.noarch
  perl-Math-BigInt-1:1.9998.39-2.amzn2023.0.2.noarch   perl-Math-BigRat-0.2624-500.amzn2023.0.2.noarch   perl-Math-Complex-1.59-477.amzn2023.0.7.noarch
  perl-URI-5.09-1.amzn2023.0.2.noarch                  perl-libnet-3.13-2.amzn2023.0.2.noarch            squid-7:6.13-1.amzn2023.0.3.x86_64

Complete!
[ec2-user@ip-10-0-1-158 ~]$ sudo vi /etc/squid/squid.conf
[ec2-user@ip-10-0-1-158 ~]$ sudo cat /etc/squid/squid.conf
#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.3.162/32
acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8             # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10          # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16         # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12          # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16         # RFC 1918 local private network (LAN)
acl localnet src fc00::/7               # RFC 4193 local private network range
acl localnet src fe80::/10              # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# This default configuration only allows localhost requests because a more
# permissive Squid installation could introduce new attack vectors into the
# network by proxying external TCP connections to unprotected services.
http_access allow localhost

# The two deny rules below are unnecessary in this default configuration
# because they are followed by a "deny all" rule. However, they may become
# critically important when you start allowing external requests below them.

# Protect web applications running on the same server as Squid. They often
# assume that only local users can access them at "localhost" ports.
http_access deny to_localhost

# Protect cloud servers that provide local users with sensitive info about
# their server via certain well-known link-local (a.k.a. APIPA) addresses.
http_access deny to_linklocal

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# For example, to allow access from your local networks, you may uncomment the
# following rule (and/or add rules that match your definition of "local"):
# http_access allow localnet
http_access allow localnet

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# 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 -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
[ec2-user@ip-10-0-1-158 ~]$ sudo systemctl enable squid
Created symlink /etc/systemd/system/multi-user.target.wants/squid.service → /usr/lib/systemd/system/squid.service.
[ec2-user@ip-10-0-1-158 ~]$ sudo systemctl start squid
[ec2-user@ip-10-0-1-158 ~]$ sudo systemctl status squid
● squid.service - Squid caching proxy
     Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; preset: disabled)
     Active: active (running) since Sat 2026-04-04 04:48:37 UTC; 4s ago
       Docs: man:squid(8)
    Process: 27592 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
   Main PID: 27594 (squid)
      Tasks: 3 (limit: 9303)
     Memory: 14.5M
        CPU: 88ms
     CGroup: /system.slice/squid.service
             ├─27594 /usr/sbin/squid --foreground -f /etc/squid/squid.conf
             ├─27596 "(squid-1)" --kid squid-1 --foreground -f /etc/squid/squid.conf
             └─27597 "(logfile-daemon)" /var/log/squid/access.log

Apr 04 04:48:37 ip-10-0-1-158.ap-southeast-1.compute.internal systemd[1]: Starting squid.service - Squid caching proxy...
Apr 04 04:48:37 ip-10-0-1-158.ap-southeast-1.compute.internal squid[27594]: Squid Parent: will start 1 kids
Apr 04 04:48:37 ip-10-0-1-158.ap-southeast-1.compute.internal squid[27594]: Squid Parent: (squid-1) process 27596 started
Apr 04 04:48:37 ip-10-0-1-158.ap-southeast-1.compute.internal systemd[1]: Started squid.service - Squid caching proxy.

これで、指定した接続元サーバーのみがSquidを利用できる状態になります。

 

プロキシサーバーの構築はこれで完了です。

 

 

■Windows Serverにプロキシの設定

次に、クライアントとなるWindows Server側で動作確認を行います。

 

いきなりプロキシ経由の通信を試すのではなく、まずはプロキシ設定なしではインターネットへ出られないことを確認しておくと、あとで差分が分かりやすくなります。

 

今回の環境では、以下の確認を実施しました。

  • Test-NetConnection aws.amazon.com -Port 443
    ⇒ HTTPS の直接接続確認
  • Invoke-WebRequest -Uri "https://aws.amazon.com/" -TimeoutSec 10
    ⇒ 実際の Web アクセス確認
  • netsh winhttp show proxy
    ⇒ WinHTTP のプロキシ設定確認

 

実際に実行してみると、

PS C:\Windows\system32> Test-NetConnection aws.amazon.com -Port 443
WARNING: TCP connect to (99.86.20.26 : 443) failed
WARNING: TCP connect to (99.86.20.109 : 443) failed
PS C:\Windows\system32> Invoke-WebRequest -Uri "https://aws.amazon.com/" -TimeoutSec 10
Invoke-WebRequest : The operation has timed out.
At line:1 char:1
+ Invoke-WebRequest -Uri "https://aws.amazon.com/" -TimeoutSec 10
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

PS C:\Windows\system32> netsh winhttp show proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

PS C:\Windows\system32>

 

結果として、TCP 接続は失敗し、Invoke-WebRequestはタイムアウトしました。

 

さらに WinHTTP の設定もDirect access (no proxy server)となっており、この時点ではプロキシ未設定であることが分かります。

 

このため、Windows Serverはプロキシなしではインターネットへ接続できない状態であると判断できます。

 

また、念のためWindows ServerからSquidサーバーの3128ポートへ到達できるかも確認しておきます。ここが疎通できていないと、あとでプロキシ設定をしても通信できません。

Test-NetConnection 10.0.1.158 -Port 3128

 

【実行結果】

PS C:\Windows\system32> Test-NetConnection 10.0.1.158 -Port 3128

ComputerName     : 10.0.1.158
RemoteAddress    : 10.0.1.158
RemotePort       : 3128
InterfaceAlias   : Ethernet
SourceAddress    : 10.0.3.162
TcpTestSucceeded : True

 

この結果でTcpTestSucceeded : Trueとなったため、Windows ServerからSquidサーバーへは問題なく到達できていることが確認できました。

 

そのうえで、PowerShellでプロキシを明示指定して Web アクセスを試します。

$proxy = "http://10.0.1.158:3128"
Invoke-WebRequest -Uri "https://aws.amazon.com/" -Proxy $proxy -UseBasicParsing -TimeoutSec 10

 

【実行結果】

PS C:\Windows\system32> Invoke-WebRequest -Uri "https://aws.amazon.com/" -Proxy $proxy -UseBasicParsing -TimeoutSec 10

                                                                                                                        StatusCode        : 200
StatusDescription :
Content           : <!doctype html>
                    <html lang="en-US" data-static-assets="https://a0.awsstatic.com" class="aws-lng-en_US">
                     <head>
                      <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: https://a...
RawContent        : HTTP/1.1 200
                    Transfer-Encoding: chunked
                    Connection: keep-alive
                    Content-Type: text/html;charset=utf-8
                    Date: Sat, 04 Apr 2026 07:18:45 GMT
                    Set-Cookie: aws-priv=eyJ2IjoxLCJldSI6MCwic3QiOjB9; Versio...
Forms             :
Headers           : {[Transfer-Encoding, chunked], [Connection, keep-alive], [Content-Type, text/html;charset=utf-8],
                    [Date, Sat, 04 Apr 2026 07:18:45 GMT]...}
Images            : {}
InputFields       : {}
Links             : {@{outerHTML=<a aria-label="Skip to main content link" class="m-sr-only m-sr-only-focusable
                    m-skip-el" href="#aws-page-content-main" id="aws-page-skip-to-main">Skip to main content</a>;
                    tagName=A; aria-label=Skip to main content link; class=m-sr-only m-sr-only-focusable m-skip-el;
                    href=#aws-page-content-main; id=aws-page-skip-to-main}, @{outerHTML=<a aria-label="Click here to
                    return to Amazon Web Services homepage" href="/?nc2=h_home"
                    data-testid="mobile-nav-item-logo-link"
                    data-rigel-analytics="{"name":"NavItem_Logo"}"><span class="rggn_38e9dfc7
                    rggn_4b9fe4a2 rggn_a1b66739 rggn_3ed66ff4 rggn_bc1a8743">
                                   <svg role="presentation" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 109 64">
<省略>

 

このコマンドではStatusCode : 200が返却され、AWSのHTMLコンテンツを取得できました。

 

つまり、プライベートサブネット上のWindows Serverから、Squidプロキシサーバーを経由してインターネットへ通信できたことになります。

 

 

■Squidのログ確認

クライアント側でHTTPのステータスコード200が返ってきていても、プロキシサーバーを本当に経由しているかを確認したい場合は、Squid のアクセスログを見るのが確実です。

sudo tail -f /var/log/squid/access.log

 

今回のログは以下の通りでした。

 
【実行結果】

1775287070.095 163314 10.0.3.162 TCP_TUNNEL/200 1008958 CONNECT aws.amazon.com:443 - HIER_DIRECT/99.86.20.11 -
1775287226.103 100537 10.0.3.162 TCP_TUNNEL/200 335032 CONNECT aws.amazon.com:443 - HIER_DIRECT/99.86.20.26 -

 

このログから分かるポイントは次の通りです。

  • 10.0.3.162
    ⇒ プロキシを利用したクライアント(Windows ServerのIP)
  • CONNECT aws.amazon.com:443
    ⇒ HTTPSアクセスのため、SquidにCONNECTメソッドでトンネル接続している
  • TCP_TUNNEL/200
    ⇒ HTTPSのトンネル接続が正常に確立し、通信が成功したことを示す
  • HIER_DIRECT/99.86.20.11
    ⇒ Squidから接続先へ直接通信していることを示す

 

このため、クライアント側の結果だけでなく、Squid側のログからも、

 

Windows Server ⇒ Squid ⇒ インターネット

 

の通信が成立していることを確認できました。

 

 

まとめ

今回は、サーバーのプロキシ設定を検証するための前準備として、Squidを使った簡単なプロキシサーバーを構築してみました。

 

初めての構築でも、Squid自体の導入は比較的シンプルで、接続元IPを許可する設定を追加すれば、検証用のプロキシサーバーとして十分に動作させることができました。

 

また、Windows Server側で「プロキシなしでは失敗」「プロキシありでは成功」という差分を確認し、さらにSquidのアクセスログからも通信経路を確認できたため、検証としては分かりやすい結果になったと思います。

 

今後は、この環境を使ってブラウザ単位のプロキシ設定や、除外設定がどのように動作するかも確認していきたいと思います。

 

 

参考リンク:Squid QUICKSTART

 

 

↓ほかの協栄情報メンバーのセキュリティについての記事を公開しています。ぜひ参考にしてみてください。
 

 
Amazon Linux 2023でSquidサーバを構築する方法(小林 剛)

 
Squidインスタンス(EC2)でプロキシ構成のハンズオン(INAMURA)

 

 

 

Last modified: 2026-04-04

Author