1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

URLフィルタリングを実装する。Nginxで出来ずSquidで実現した。

Posted at

特定のURLにだけアクセスさせたい

  • やりたいことは実はこれだけです。
  • 所謂、ホワイトリスト運用というものです。
  • もう少し詳しく書くと**「全てのインターネットアクセスを遮断した上で、ホワイトリストに記載されたサイトだけアクセス許可したい」**というものです。

最初はNginxで・・・断念したけど、出来るかもしれない

  • 書いた通りです。一番慣れていたので、Nginxで試みたのですが、上手く出来ませんでした。

だからSquidでやることにした

  • この方の記事が非常に役に立ちました。
  • この場をお借りして、厚く御礼申し上げます。

環境

  • AWS EC2 Ubuntu18.04
squid -v
Squid Cache: Version 3.5.27
Service Name: squid
Ubuntu linux

インストールと起動確認等

apt install squid
sudo systemctl status squid.service

ちなにみ停止・起動・再起動
sudo systemctl stop squid.service
sudo systemctl start squid.service
sudo systemctl restart squid.service

configの変更

  • 変更箇所
/etc/squid$ diff squid.conf squid.conf.org
1192,1193c1192
< acl whitelist dstdomain "/etc/squid/whitelist"
< http_access allow whitelist
---
>
  • 場所に注意が必要なので、入れた箇所を
  • vimで開いて、「:set nu」しています。
  • **許可設定は「1195行目の設定より上に入れる必要がある」**らしいです。
-- snip --
1186
1187 # Example rule allowing access from your local networks.
1188 # Adapt localnet in the ACL section to list your (internal) IP networks
1189 # from where browsing should be allowed
1190 #http_access allow localnet
1191 http_access allow localhost
1192 acl whitelist dstdomain "/etc/squid/whitelist"
1193 http_access allow whitelist
1194 # And finally deny all other access to this proxy
1195 http_access deny all
1196
-- snip --

ホワイトリストの定義

  • 参考にさせて頂いた記事通りに設定していますが、念のため添付します。
ls -l
total 584
-rw-r--r-- 1 root root   1817 Sep  2 15:35 errorpage.css
-rw-r--r-- 1 root root 290935 Dec 14 07:41 squid.conf
-rw-r--r-- 1 root root 290861 Sep  2 15:35 squid.conf.org
-rw-r--r-- 1 root root     24 Dec 14 07:35 whitelist

cat whitelist
.qiita.com
.google.com

pwd
/etc/squid

以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?