【Squid】プロキシサーバ / Squid ~ 設定ファイル編 ~

■ はじめに

Proxy サーバの Squid に関する 設定ファイル squid.conf について扱う

目次

【1】ファイル格納場所
【2】説明
 1)acl (アクセスコントロールリスト)
 2)http_access (HTTPアクセス)
【3】関連コマンド
 1)設定の反映
 2)文法チェック
【4】サンプル

【1】ファイル格納場所

* デフォルトなら「/etc/squid/squid.conf」

【2】説明

1)acl (アクセスコントロールリスト)

* アクセス権限を示す

acl [アクセスコントロール名] [タイプ] [パラメータ]

2)http_access (HTTPアクセス)

* 許可/拒否を示す

http_access allow/deny [!]acl名

【3】関連コマンド

1)設定の反映

sudo systemctl reload squid

2)文法チェック

# 設定ファイル「squid.conf」の文法チェックには以下のコマンドを実行
# 文法チェック
sudo squid -k check

# 設定ファイルのリロード(既存セッションに影響なく反映可能)
squid -k reconfigure

【4】サンプル

* コメント文以外はデフォルト設定

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
#
# 【1】ローカルネットワークの定義
# acl [アクセスコントロール名] src [IP/Netmask]
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

# 【2】ポート番号の定義
# acl [アクセスコントロール名] port [ポート番号]
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

# CONNECTメソッドはプロキシサーバにトンネリングを要求するメソッド
# SSLなどで暗号化されたデータを送る場合に利用
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
#
# 【3】【2】で定義した接続先として指定されているポート以外を拒否
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
#
# 【4】SSL接続時に 443 ポート以外の CONNECT を拒否
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
#
# 【5】自身からのアクセス(localhost)及びキャッシュマネージャ/cachemgr.cgi(manager)からのアクセスを許可
#       + Squid の統計情報を出力するのが、キャッシュマネージャと呼ばれる CGI スクリプト
#         キャッシュマネージャは /usr/lib/squid/cachemgr.cgi にインストールされている
http_access allow localhost manager
http_access deny manager

# 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
#
# 【6】【1】で定義したローカルネットワーク(localnet)
#        及び自身からのアクセス(localhost)からのアクセスを許可
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
#
# 【7】 【3】~【6】に一致しなかった場合は拒否
http_access deny all

# Squid normally listens to port 3128
#
# 【8】Squid で使用するポート
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
#
# 【9】コアダンプを吐き出すディレクトリを指定
coredump_dir /var/spool/squid

#
# Add any of your own refresh_pattern entries above these.
#
# 【10】キュッシュの保存期間をコントロールするための設定
# 
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

参考文献

http://blog.cybozu.io/entry/2017/02/03/080000
http://www.turbolinux.co.jp/products/server/11s/user_guide/squidconfig.html
http://biraprog.hatenablog.jp/entry/2014/07/23/211230
http://www.atmarkit.co.jp/ait/articles/0904/08/news120_2.html
refresh_pattern
http://d.hatena.ne.jp/takami_hiroki/20101006/p1

関連記事

【ネットワーク】プロキシ / Proxy
https://dk521123.hatenablog.com/entry/2017/08/08/224300
プロキシサーバ / SquidLinux / 初期設定編 ~
https://dk521123.hatenablog.com/entry/2017/06/23/223438
プロキシサーバ / SquidLinux / Basic認証編 ~
https://dk521123.hatenablog.com/entry/2017/06/26/224311
プロキシサーバ / SquidLinux / SSLプロキシ構築編 ~
https://dk521123.hatenablog.com/entry/2017/06/24/235123
プロキシサーバ / Squid ~ ログ編 ~
https://dk521123.hatenablog.com/entry/2024/02/01/000000
プロキシサーバ / Squid ~ Whitelist編 ~
https://dk521123.hatenablog.com/entry/2024/02/06/002541