【squid】初心者でも出来る!ブロックページのカスタマイズ方法解説【proxyサーバー】

Winodws
この記事は約27分で読めます。

「squid」でブロックページが英語のままになってしまう」

「squid」でブロックページを日本語でカスタマイズしたい

そんなふうに思ったことはありませんか?

じつは「squid」ではブロックページのカスタマイズをすることができます

今回はsquidで表示されるブロックページの編集方法について解説します。

実際に検証を行い実際に躓いた点など踏まえて経験ベースでお伝えしていきたいと思います。

はじめに

本記事ではsquidのフィルタリング機能でwebサイトへのアクセスが制限されたときに表示されるブロックページについて解説していきます。

もし、squidを使われたことがない、もしくはsquidのACLはよくわからない方は以下記事を参考にしてみください。

ブロックページとは

webフィルタリングについて先に補足しておきます。

webとは、特定のサイトへのアクセスを止めることができる機能を指します。

検証環境について

今回は、Virtual boxを活用してsquidのwebフィルタリングを検証していきます。

検証環境で使用する仮想マシンのOSバージョンは以下の通りになります。

  • Virtual box
    バージョン 7.2.4 r170995
  • Windows Server 2022 Datacenter Evaluation
    バージョン 21H2 OS ビルド 20348.587
  • Windows 11 Enterprise Evaluation
    バージョン 24H2 OS ビルド 26100.6899

※Windows Server 2022が「Datacenter Evaluation」になっていますが、特に意味はありません。

プロキシサーバーとクライアントのホスト名とIPアドレスの割り当ては以下の通りです。

役割OSホスト名IPアドレス
プロキシサーバーWindows Serverproxy-svr-0110.0.2.15 /24
クライアントPCWindows 11proxy-client-0110.0.2.10 /24

今回の検証のゴールは以下の通りとします。

ゴール
  • 特定のサイト(http://example.com)へのアクセス制限を設定し、ブロックページを表示させる
  • カスタマイズしたブロックページを表示させる

httpのサイトで検証

http://example.com

squid デフォルトで表示されるブロックページ

squidではACLで許可されていないサイトへhttpでアクセスした際に以下の画面が表示されます。

squid ブロックページ カスタマイズ手順

検証イメージのゴール

今回は、先ほどのデフォルトのブロック画面から以下画像のようなブロックページを作っていきたいと思います。

html、cssを編集する必要がありますが、初心者でも再現できるようにコードはコピーできるようにしてあります!

設定までのステップ
  • squidのconfファイル内にてエラーページを表示させる設定を追記する
  • 日本語用のエラーページのhtmlファイルを編集する

では早速いきましょう。

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.0.0/8	# RFC1918 possible internal network
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network
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
acl CONNECT method CONNECT

#検証用のALC定義を追加
acl deny_mysite_test_1 dstdomain .example.com

#
# Recommended minimum Access Permission configuration:
#

#検証用のALCを適用
http_access deny deny_mysite_test_1

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

# 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

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

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

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

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

# Squid normally listens to port 3128
http_port 3128

# Uncomment the line below to enable disk caching - path format is /cygdrive/<full path to cache folder>, i.e.
#cache_dir aufs /cygdrive/d/squid/cache 3000 16 256


# Leave coredumps in the first cache dir
coredump_dir /var/cache/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

dns_nameservers 8.8.8.8 208.67.222.222

max_filedescriptors 3200

# ブロック時は Squid 標準ページを表示(リダイレクトしない)
deny_info ERR_ACCESS_DENIED deny_mysite_test_1

#日本語用のエラーページを表示
error_directory C:/Squid/usr/share/squid/errors/ja

入力が完了したら、confファイルは保存します。

設定を反映させるために、Squid Terminalにて以下コマンドを実行します。

設定を再読み込みさせるコマンドになります。

squid -k reconfigure

やり方がわからない方は、squidの再起動でも問題ありません。

設定の反映が完了したら、クライアント端末からexample.comへhttpアクセスを行います。

http://example.com

デフォルトのブロックページが表示されていれば、一旦OKです。

この後にブロックページのカスタマイズを行っていきます。

エラーページのhtmlファイルを編集する

squidではプロキシサーバーで通信を遮断した際に表示するエラーページに関して、

各言語ごとに対応可能なエラーページのhtmlテンプレートがフォルダー内に格納されています。

C:\Squid\usr\share\squid\errors

日本語対応のエラーページが格納されているフォルダは以下の通りです。

フォルダーパスはこちらになります。

C:\Squid\usr\share\squid\errors\ja\ERR_ACCESS_DENIED

ERR_ACCESS_DENIEDファイルを開くとエラーページのhtmlの中身は以下の通りです。

もしファイルを開く際に「このファイルを開く方法を選んでください」と表示された場合、
メモ帳を選択します。

※お使いのテキストエディターがあればそちらでも構いません。

※見やすいようにファイル内のコードはインデントや改行で整理してあります。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>エラー: リクエストされた URL は取得できませんでした</title>
    <style type="text/css">
      <!--
      %l
      body :lang(fa) {
        direction: rtl;
        font-size: 100%;
        font-family: Tahoma, Roya, sans-serif;
        float: right;
      }
      :lang(he) {
        direction: rtl;
      }
      -->
    </style>
  </head>
  <body id=%c>
    <div id="titles">
      <h1>ERROR</h1>
      <h2>The requested URL could not be retrieved</h2>
    </div>
    <hr>
    <div id="content">
      <p>
        The following error was encountered while trying to retrieve the URL:
        <a href="%U">%U</a>
      </p>
      <blockquote id="error">
        <p><b>アクセスを拒否されました。</b></p>
      </blockquote>
      <p>
        Access control configuration prevents your request from being allowed at this time.
        Please contact your service provider if you feel this is incorrect.
      </p>
      <p>
        Your cache administrator is <a href="mailto:%w%W">%w</a>.
      </p>
      <br>
    </div>
    <hr>
    <div id="footer">
      <p>%Tに%h (%s)が生成しました。</p>
      <!-- %c -->
    </div>
  </body>
</html>

このファイルの中身を書き換えていきます。

うまくいかなかった場合も想定して、バックアップを取っておくことをお勧めします。

書き換える構文は以下の通りです。

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>アクセスが拒否されました</title>
<style>
body {
  font-family: "Segoe UI", "Meiryo", sans-serif;
  background-color: #f6f8fa;
  color: #333;
  margin: 40px;
}
.container {
  background: #fff;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
h1 {
  color: #b22222;
}
p {
  margin-top: 1em;
  line-height: 1.6;
}
hr {
  margin-top: 2em;
  border: none;
  border-top: 1px solid #ccc;
}
.footer {
  font-size: 12px;
  color: #666;
  margin-top: 1em;
}
</style>
</head>
<body>
<div class="container">
  <h1>アクセスが拒否されました</h1>
  <p>申し訳ありません。このWebサイト(<strong>%U</strong>)へのアクセスは、プロキシサーバーのポリシーによりブロックされています。</p>
  <p>必要な場合は、システム管理者にお問い合わせください。</p>
  <hr>
  <div class="footer">
    <p>%T に %h (%s) が生成しました。</p>
  </div>
</div>
</body>
</html>

面倒な方は下記コードをコピーして、先ほどのERR_ACCESS_DENIEDファイルにペーストして保存すればOK

C:\Squid\usr\share\squid\errors\ja\ERR_ACCESS_DENIED

ペースト後のファイル内の中身を一部ご紹介するとこんな感じになります。

構文の書き換えができましたら、ファイルを保存していきます。

こちらは普通にCtrl + Sで保存してもらえれば大丈夫です。保存後はファイルを閉じます。

ブロックページの動作確認

残りは動作確認のみです。

squidに設定を再読み込みさせていきましょう。

squid Terminalを開き、再読み込みのコマンドを入力していきます。

squid -k reconfigure

これでサーバー側の操作は終了です。

今度はクライアント端末から再度example.comへ再アクセスを行います。

以下の通り、ブロックページの表示内容が変わっていれば、設定は成功です!

squid ブロックページ 表示されない場合

ここからは表示されない場合の対処法について解説していきます。

構文チェックが間違っていないか

まずは、confファイルに入力したコマンド内容が誤っていないかチェックしていきます。

プロキシサーバー側で以下コマンドを実行します。

squid -k parse

このコマンドは、squidの構文チェックのコマンドになります。

問題ない場合は、「Processing」と表示されます。

どこか構文エラーがある場合は、以下コードの青文字の通りエラーが返されます。

今回の場合は、エラーページを指定する際のディレクトリにおいて、フォルダーパスに一部誤りがあったことでエラーが発生しています。

「errors_directory /usr/share/squid/errors/ja」

C:\Squid>squid -k parse
2025/11/08 20:04:24| Startup: Initializing Authentication Schemes ...
2025/11/08 20:04:24| Startup: Initialized Authentication Scheme 'basic'
2025/11/08 20:04:24| Startup: Initialized Authentication Scheme 'digest'
2025/11/08 20:04:24| Startup: Initialized Authentication Scheme 'negotiate'
2025/11/08 20:04:24| Startup: Initialized Authentication Scheme 'ntlm'
2025/11/08 20:04:24| Startup: Initialized Authentication.
2025/11/08 20:04:24| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2025/11/08 20:04:24| Processing: acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
2025/11/08 20:04:24| Processing: acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
2025/11/08 20:04:24| Processing: acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
2025/11/08 20:04:24| Processing: acl localnet src fc00::/7       # RFC 4193 local private network range
2025/11/08 20:04:24| Processing: acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
2025/11/08 20:04:24| Processing: acl SSL_ports port 443
2025/11/08 20:04:24| Processing: acl Safe_ports port 80         # http
2025/11/08 20:04:24| Processing: acl Safe_ports port 21         # ftp
2025/11/08 20:04:24| Processing: acl Safe_ports port 443                # https
2025/11/08 20:04:24| Processing: acl Safe_ports port 70         # gopher
2025/11/08 20:04:24| Processing: acl Safe_ports port 210                # wais
2025/11/08 20:04:24| Processing: acl Safe_ports port 1025-65535 # unregistered ports
2025/11/08 20:04:24| Processing: acl Safe_ports port 280                # http-mgmt
2025/11/08 20:04:24| Processing: acl Safe_ports port 488                # gss-http
2025/11/08 20:04:24| Processing: acl Safe_ports port 591                # filemaker
2025/11/08 20:04:24| Processing: acl Safe_ports port 777                # multiling http
2025/11/08 20:04:24| Processing: acl CONNECT method CONNECT
2025/11/08 20:04:24| Processing: acl deny_mysite_test dstdomain .kuwamakurano98.com
2025/11/08 20:04:24| Processing: acl deny_mysite_test_1 dstdomain .example.com
2025/11/08 20:04:24| Processing: http_access deny deny_mysite_test
2025/11/08 20:04:24| Processing: http_access deny deny_mysite_test_1
2025/11/08 20:04:24| Processing: http_access allow localhost manager
2025/11/08 20:04:24| Processing: http_access deny manager
2025/11/08 20:04:24| Processing: http_access deny !Safe_ports
2025/11/08 20:04:24| Processing: http_access deny CONNECT !SSL_ports
2025/11/08 20:04:24| Processing: http_access allow localnet
2025/11/08 20:04:24| Processing: http_access allow localhost
2025/11/08 20:04:24| Processing: http_access deny all
2025/11/08 20:04:24| Processing: http_port 3128
2025/11/08 20:04:24| Processing: coredump_dir /var/cache/squid
2025/11/08 20:04:24| Processing: refresh_pattern ^ftp:          1440    20%     10080
2025/11/08 20:04:24| Processing: refresh_pattern ^gopher:       1440    0%      1440
2025/11/08 20:04:24| Processing: refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
2025/11/08 20:04:24| Processing: refresh_pattern .              0       20%     4320
2025/11/08 20:04:24| Processing: dns_nameservers 8.8.8.8 208.67.222.222
2025/11/08 20:04:24| Processing: max_filedescriptors 3200
2025/11/08 20:04:24| Processing: deny_info ERR_ACCESS_DENIED deny_mysite_test_1
2025/11/08 20:04:24| Processing: errors_directory /usr/share/squid/errors/ja
2025/11/08 20:04:24| /etc/squid/squid.conf:91 unrecognized: 'errors_directory'
2025/11/08 20:04:24| Initializing https:// proxy context

実際に修正して、再度構文をチェックした実行結果は以下の通りです。

正常な状態が確認できます。

C:\Squid>squid -k parse
2025/11/08 20:08:01| Startup: Initializing Authentication Schemes ...
2025/11/08 20:08:01| Startup: Initialized Authentication Scheme 'basic'
2025/11/08 20:08:01| Startup: Initialized Authentication Scheme 'digest'
2025/11/08 20:08:01| Startup: Initialized Authentication Scheme 'negotiate'
2025/11/08 20:08:01| Startup: Initialized Authentication Scheme 'ntlm'
2025/11/08 20:08:01| Startup: Initialized Authentication.
2025/11/08 20:08:01| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2025/11/08 20:08:01| Processing: acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
2025/11/08 20:08:01| Processing: acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
2025/11/08 20:08:01| Processing: acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
2025/11/08 20:08:01| Processing: acl localnet src fc00::/7       # RFC 4193 local private network range
2025/11/08 20:08:01| Processing: acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
2025/11/08 20:08:01| Processing: acl SSL_ports port 443
2025/11/08 20:08:01| Processing: acl Safe_ports port 80         # http
2025/11/08 20:08:01| Processing: acl Safe_ports port 21         # ftp
2025/11/08 20:08:01| Processing: acl Safe_ports port 443                # https
2025/11/08 20:08:01| Processing: acl Safe_ports port 70         # gopher
2025/11/08 20:08:01| Processing: acl Safe_ports port 210                # wais
2025/11/08 20:08:01| Processing: acl Safe_ports port 1025-65535 # unregistered ports
2025/11/08 20:08:01| Processing: acl Safe_ports port 280                # http-mgmt
2025/11/08 20:08:01| Processing: acl Safe_ports port 488                # gss-http
2025/11/08 20:08:01| Processing: acl Safe_ports port 591                # filemaker
2025/11/08 20:08:01| Processing: acl Safe_ports port 777                # multiling http
2025/11/08 20:08:01| Processing: acl CONNECT method CONNECT
2025/11/08 20:08:01| Processing: acl deny_mysite_test dstdomain .kuwamakurano98.com
2025/11/08 20:08:01| Processing: acl deny_mysite_test_1 dstdomain .example.com
2025/11/08 20:08:01| Processing: http_access deny deny_mysite_test
2025/11/08 20:08:01| Processing: http_access deny deny_mysite_test_1
2025/11/08 20:08:01| Processing: http_access allow localhost manager
2025/11/08 20:08:01| Processing: http_access deny manager
2025/11/08 20:08:01| Processing: http_access deny !Safe_ports
2025/11/08 20:08:01| Processing: http_access deny CONNECT !SSL_ports
2025/11/08 20:08:01| Processing: http_access allow localnet
2025/11/08 20:08:01| Processing: http_access allow localhost
2025/11/08 20:08:01| Processing: http_access deny all
2025/11/08 20:08:01| Processing: http_port 3128
2025/11/08 20:08:01| Processing: coredump_dir /var/cache/squid
2025/11/08 20:08:01| Processing: refresh_pattern ^ftp:          1440    20%     10080
2025/11/08 20:08:01| Processing: refresh_pattern ^gopher:       1440    0%      1440
2025/11/08 20:08:01| Processing: refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
2025/11/08 20:08:01| Processing: refresh_pattern .              0       20%     4320
2025/11/08 20:08:01| Processing: dns_nameservers 8.8.8.8 208.67.222.222
2025/11/08 20:08:01| Processing: max_filedescriptors 3200
2025/11/08 20:08:01| Processing: deny_info ERR_ACCESS_DENIED deny_mysite_test_1
2025/11/08 20:08:01| Processing: error_directory /usr/share/squid/errors/ja
2025/11/08 20:08:01| Initializing https:// proxy context

C:\Squid>

最後に

今回は、squidで表示されるブロックページのカスタマイズ方法について解説しました。

コメント

タイトルとURLをコピーしました