重构squid
This commit is contained in:
parent
cdb2289a64
commit
49116c6d58
23
config/squid.conf
Normal file → Executable file
23
config/squid.conf
Normal file → Executable file
@ -5,7 +5,24 @@ auth_param basic realm Squid proxy-caching web server
|
||||
auth_param basic credentialsttl 2 hours
|
||||
acl auth_users proxy_auth REQUIRED
|
||||
http_access allow auth_users
|
||||
http_access deny all
|
||||
|
||||
# 缓存配置
|
||||
cache_dir ufs /var/cache/squid 100 16 256
|
||||
cache_mem 256 MB
|
||||
maximum_object_size 50 MB
|
||||
|
||||
# 日志与PID
|
||||
pid_filename /tmp/squid.pid
|
||||
cache_log /dev/null
|
||||
access_log none
|
||||
cache_store_log none
|
||||
cache_log /var/log/squid/cache.log
|
||||
cache_store_log /var/log/squid/store.log
|
||||
|
||||
# 日志轮转设置
|
||||
logfile_rotate 10
|
||||
|
||||
# 自定义日志格式(年月日时分秒)
|
||||
logformat custom_format %{%Y/%m/%d %H:%M:%S}tl.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %[un] %Sh/%<A %mt
|
||||
access_log /var/log/squid/access.log custom_format
|
||||
|
||||
# 强制使用英语错误页面(可选)
|
||||
error_directory /usr/share/squid/errors/en
|
||||
|
||||
@ -11,13 +11,14 @@ services:
|
||||
restart: always
|
||||
|
||||
squid:
|
||||
image: ckazi/squid
|
||||
image: squid
|
||||
container_name: squid
|
||||
ports:
|
||||
- "51822:3128"
|
||||
volumes:
|
||||
- ./config/squid.conf:/etc/squid/squid.conf:ro
|
||||
- ./config/squid_passwd:/etc/squid/squid_passwd:ro
|
||||
- ./log:/var/log/squid:rw
|
||||
depends_on:
|
||||
- squid-ui
|
||||
restart: always
|
||||
|
||||
@ -3,15 +3,22 @@ FROM alpine:latest
|
||||
# 安装 Squid
|
||||
RUN apk add --no-cache squid
|
||||
|
||||
# 创建缓存目录并设置权限
|
||||
RUN mkdir -p /var/cache/squid \
|
||||
&& chown -R squid:squid /var/cache/squid
|
||||
# 创建必要的目录并设置权限
|
||||
RUN mkdir -p \
|
||||
/var/cache/squid \
|
||||
/var/log/squid \
|
||||
/var/run \
|
||||
&& chown -R squid:squid /var/cache/squid \
|
||||
&& chown -R squid:squid /var/log/squid
|
||||
|
||||
# 复制配置文件(或通过挂载)
|
||||
#COPY squid.conf /etc/squid/squid.conf
|
||||
# 复制配置文件
|
||||
COPY squid.conf /etc/squid/squid.conf
|
||||
COPY start-squid.sh /usr/local/bin/start-squid.sh
|
||||
|
||||
RUN chmod +x /usr/local/bin/start-squid.sh
|
||||
|
||||
USER squid
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 3128
|
||||
|
||||
# 启动命令
|
||||
CMD ["squid", "-N", "-f", "/etc/squid/squid.conf"]
|
||||
ENTRYPOINT ["/usr/local/bin/start-squid.sh"]
|
||||
|
||||
28
squid/squid.conf
Executable file
28
squid/squid.conf
Executable file
@ -0,0 +1,28 @@
|
||||
http_port 3128
|
||||
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/squid_passwd
|
||||
auth_param basic children 5
|
||||
auth_param basic realm Squid proxy-caching web server
|
||||
auth_param basic credentialsttl 2 hours
|
||||
acl auth_users proxy_auth REQUIRED
|
||||
http_access allow auth_users
|
||||
http_access deny all
|
||||
|
||||
# 缓存配置
|
||||
cache_dir ufs /var/cache/squid 100 16 256
|
||||
cache_mem 256 MB
|
||||
maximum_object_size 50 MB
|
||||
|
||||
# 日志与PID
|
||||
pid_filename /tmp/squid.pid
|
||||
cache_log /var/log/squid/cache.log
|
||||
cache_store_log /var/log/squid/store.log
|
||||
|
||||
# 日志轮转设置
|
||||
logfile_rotate 10
|
||||
|
||||
# 自定义日志格式(年月日时分秒)
|
||||
logformat custom_format %{%Y/%m/%d %H:%M:%S}tl.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %[un] %Sh/%<A %mt
|
||||
access_log /var/log/squid/access.log custom_format
|
||||
|
||||
# 强制使用英语错误页面(可选)
|
||||
error_directory /usr/share/squid/errors/en
|
||||
31
squid/start-squid.sh
Normal file
31
squid/start-squid.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
CHOWN=$(/usr/bin/which chown)
|
||||
SQUID=$(/usr/bin/which squid)
|
||||
|
||||
prepare_folders() {
|
||||
echo "Preparing folders..."
|
||||
mkdir -p /var/cache/squid/
|
||||
mkdir -p /var/log/squid/
|
||||
"$CHOWN" -R squid:squid /var/cache/squid/
|
||||
"$CHOWN" -R squid:squid /var/log/squid/
|
||||
}
|
||||
|
||||
initialize_cache() {
|
||||
echo "Initializing cache..."
|
||||
if [ ! -d "/var/cache/squid/00" ]; then
|
||||
"$SQUID" -z
|
||||
sleep 5
|
||||
fi
|
||||
}
|
||||
|
||||
run() {
|
||||
echo "Starting squid..."
|
||||
prepare_folders
|
||||
initialize_cache
|
||||
exec "$SQUID" -NYCd 1 -f /etc/squid/squid.conf
|
||||
}
|
||||
|
||||
run
|
||||
Loading…
x
Reference in New Issue
Block a user