サーバー構築

Squidでプロキシサーバーを構築

Squidでプロキシサーバーを構築
目次
  1. Squid(Proxy)をインストール
  2. squid.conf 編集
  3. パスワードファイルの作成
  4. 再起動(設定反映)
  5. ブラウザーにプロキシサーバーを設定する

今回、構築するプロキシサーバーは、クライアント側で利用するプロキシです。主にブラウザーに設定して利用します。一般的に「串」と呼ばれているもので、パスワード認証付きです。WEBサーバーと一緒に使う様なリバースプロキシではありません。

2026年11月時点の補足:設定の名前が変わっています

この記事は2013年(Squid 2 系)の設定です。Debian 13 の Squid は 6.13 で、記事の設定のうち次の2つはそのままでは動きません。

項目この記事(Squid 2 系)Debian 13(Squid 6.13)
認証プログラム/usr/lib/squid/ncsa_auth/usr/lib/squid/basic_ncsa_auth(パッケージのファイル一覧で確認)
ヘッダーの削除header_accessrequest_header_access(送る側)/ reply_header_access(返ってくる側)
再起動/etc/init.d/squid restartsystemctl restart squid
パスワードファイルの作成htpasswd(Apache 付属)htpasswd(apache2-utils を入れる)
# apt install squid apache2-utils
# htpasswd -c /etc/squid/passwd user

auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
acl password proxy_auth REQUIRED
http_access allow password
http_access deny all
request_header_access Via deny all
request_header_access X-Forwarded-For deny all
http_port 8080

# squid -k parse
# systemctl restart squid

⚠ 認証の無いプロキシをインターネットに公開すると、すぐに踏み台として使われます。http_access deny all を必ず最後に置き、ポートはファイアウォールで使う人の IP だけに絞ってください。

このプロキシサーバーの使い道として、社内ネットワークから外部に出たりする時に利用したり、特定のサーバーにアクセスする時に、このプロキシサーバー経由のみを許可するなど色々な使い道があります。

では、さっそく構築しておきましょう!

Squid(Proxy)をインストール

// インストール
# apt-get install squid

squid.conf 編集

// 編集
# vi /etc/squid/squid.conf

// ~省略~

-auth_param basic program 
+auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd ← 変更:パスワードファイル名を指定する。

// ~省略~

#acl password proxy_auth REQUIRED
acl password proxy_auth REQUIRED ← 変更:認証用acl名を追加する。

// ~省略~

-acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
+acl localnet src 192.168.0.0/24 # RFC1918 possible internal network ← 変更:ローカルネットワークを変更する。

// ~省略~

// http_access allow localhost の下へ記述
http_access allow localhost
+http_access allow password ← 追加:パスワード認証を許可する。

// ~省略~

-http_port 3128
+http_port 8080 ← 変更:デフォルトポートを変更する。

// ~省略~

#  TAG: header_access
#	Usage: header_access header_name allow|deny [!]aclname ...
#
#	WARNING: Doing this VIOLATES the HTTP standard.  Enabling
#	this feature could make you liable for problems which it
#	causes.
#
#	This option replaces the old 'anonymize_headers' and the
#	older 'http_anonymizer' option with something that is much
#	more configurable. This new method creates a list of ACLs
#	for each header, allowing you very fine-tuned header
#	mangling.
#
#	You can only specify known headers for the header name.
#	Other headers are reclassified as 'Other'. You can also
#	refer to all the headers with 'All'.
#
#	For example, to achieve the same behavior as the old
#	'http_anonymizer standard' option, you should use:
#
#		header_access From deny all
#		header_access Referer deny all
#		header_access Server deny all
#		header_access User-Agent deny all
#		header_access WWW-Authenticate deny all
#		header_access Link deny all
#
#	Or, to reproduce the old 'http_anonymizer paranoid' feature
#	you should use:
#
#		header_access Allow allow all
#		header_access Authorization allow all
#		header_access WWW-Authenticate allow all
#		header_access Proxy-Authorization allow all
#		header_access Proxy-Authenticate allow all
#		header_access Cache-Control allow all
#		header_access Content-Encoding allow all
#		header_access Content-Length allow all
#		header_access Content-Type allow all
#		header_access Date allow all
#		header_access Expires allow all
#		header_access Host allow all
#		header_access If-Modified-Since allow all
#		header_access Last-Modified allow all
#		header_access Location allow all
#		header_access Pragma allow all
#		header_access Accept allow all
#		header_access Accept-Charset allow all
#		header_access Accept-Encoding allow all
#		header_access Accept-Language allow all
#		header_access Content-Language allow all
#		header_access Mime-Version allow all
#		header_access Retry-After allow all
#		header_access Title allow all
#		header_access Connection allow all
#		header_access Proxy-Connection allow all
#		header_access All deny all
#
#	By default, all headers are allowed (no anonymizing is
#	performed).
#
#Default:
# none
header_access Referer deny all ← 追加:参照元URLの非表示

// 追加:ユーザーエージェントを非表示。非表示にした場合、アクセス出来ないサイトが増えるのでオフ。
#header_access User-Agent deny all

# 追加:プロクシ経由でアクセスしているのを通知しない。
header_access Via deny all
header_access Cache-Control deny all
header_access X-Forwarded-For deny all
----- 中略 -----
#  TAG: visible_hostname
#	If you want to present a special hostname in error messages, etc,
#	define this.  Otherwise, the return value of gethostname()
#	will be used. If you have multiple caches in a cluster and
#	get errors about IP-forwarding you must set them to have individual
#	names with this setting.
#
#Default:
# none

visible_hostname unknown ← 追加:プロキシサーバーのホスト名を非表示する。
----- 中略 -----
-forwarded_for on
+forwarded_for off ← 変更:接続元IPアドレスを隠蔽する。
----- 下略 -----

パスワードファイルの作成

// 新規作成
# htpasswd -c /etc/squid/passwd user
New password:******* ← パスワードを入力
Re-type new password:******* ← もう一度パスワードを入力
Adding password for user user

再起動(設定反映)

// 再起動
# /etc/init.d/squid restart

ここまででプロキシサーバーの構築は終わりです。

ブラウザーにプロキシサーバーを設定する

ブラウザーのプロキシ設定を開いて下さい。

インターネットのプロパティ → ローカルエリアネットワーク(LAN)の設定 → プロキシサーバー

アドレス:今回、構築したサーバーのIP、またはドメイン
ポート:8080

設定後にブラウザーを開くと、ユーザーとパスワードの入力を求められるので、上記で設定した情報を入力するとプロキシ経由でインターネットに接続できるようになります。

今回、構築したプロキシサーバーがインターネットに出来ない環境の場合、このサーバーを経由してもインターネットには接続できませんのでご注意下さい。^^;

2026年11月時点の補足:Debian 13 の Squid の版

このサイトを置いている Debian 13.7 の VPSで候補の版を確かめました(2026年11月5日)。Debian 13 の Squid は 6.13 で、セキュリティ更新が出ています。

$ apt-cache policy squid | head -3
squid:
  Installed: (none)
  Candidate: 6.13-2+deb13u4
項目この記事(2013年)Debian 13(2026年11月時点)
パッケージ名squid3squid(6.13)
設定ファイル/etc/squid3/squid.conf/etc/squid/squid.conf
再起動/etc/init.d/squid3 restartsystemctl restart squid
設定の確認—squid -k parse
使うポート用途
3128番/TCPプロキシ(記事の既定のまま)
開ける相手自分の IP だけ(誰でも使えると踏み台にされる)

Debian の版は Debian のパッケージ一覧(madison) でも確認しました。