proxyサーバ squidでアクセス時に認証を要求する設定

スポンサーリンク
スポンサーリンク

CentOS6 64bitでのProxyサーバ squidで、digest認証/basic認証でユーザ名/パスワードを要求するようにする設定ファイルです。
basic認証、digest認証それぞれの場合の squid.conf です。
違いは先頭の auth_param の行と、パスワードファイルの生成方法です。パスワードファイルの作成で、認証時に要求されるユーザ名/パスワードを設定します。

設定

basic認証の場合

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

htpasswd -cm /etc/squid/.htpasswd ユーザ名

実行後、パスワードの入力を求められますので、入力します。
2019.3.3 修正
オプションを -m から -cm にしました。
2019.3.3時点では、m を付けないと、ベーシック認証で8文字を超えるパスワードを設定できないようです

/etc/squid/squid.conf

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/.htpasswd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
acl pauth proxy_auth REQUIRED
http_access allow pauth
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
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
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
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_port 8080
cache_mem 32 MB
cache_dir ufs /var/spool/squid 4000 16 256
maximum_object_size 65536 KB
forwarded_for off
request_header_access Referer deny all
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all
access_log /var/log/squid/access.log auto
emulate_httpd_log on
cache_effective_user squid

digest認証の場合

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

htpasswd -bcp /etc/squid/passwd ユーザ名 パスワード

/etc/squid/passwd ファイルには、パスワードがそのまま記述されますので、注意!

/etc/squid/squid.conf

auth_param digest program /usr/lib64/squid/digest_pw_auth /etc/squid/passwd
auth_param digest children 20 startup=0 idle=1
auth_param digest realm proxy
auth_param digest nonce_garbage_interval 5 minutes
auth_param digest nonce_max_duration 30 minutes
auth_param digest nonce_max_count 50
acl pauth proxy_auth REQUIRED
http_access allow pauth
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
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
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
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_port 8080
cache_mem 32 MB
cache_dir ufs /var/spool/squid 4000 16 256
maximum_object_size 65536 KB
forwarded_for off
request_header_access Referer deny all
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all
access_log /var/log/squid/access.log auto
emulate_httpd_log on
cache_effective_user squid

参考

まったりSEのインフラ構築メモ |SquidプロキシでDigest認証
プロキシサーバー構築(Squid) – CentOSで自宅サーバー構築
http://www.oss-d.net/squid/2.6” target=”_blank”>プロキシサーバ/Squid – OSSでLinuxサーバ構築

コメント

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