Squid Web Cache Wiki

Squid Web Cache 文档

🔗 门户闪屏页面

🔗 目录

当 Squid 作为 Web 门户时,有时需要向用户展示服务协议、访问条款、广告或其他初始显示内容。

🔗 浏览会话

此配置会将新访问者重定向到一个初始闪屏页面,然后在可配置的时间内允许访问,之后会重新显示闪屏页面。在此期间的进一步访问将延长他们的会话。如果访问者消失的时间超过会话超时时间,任何新请求都会被重定向回闪屏页面,并启动一个新的会话。

从 1.1 版的会话助手开始,可以使用“-T”选项代替“-t”。这将提供一个固定的超时时间,迫使闪屏页面定期显示。

🔗 HTTP 状态 511

强制门户闪屏页面会在截获的流量响应上使客户端软件感到困惑。客户端软件可能会将闪屏页面误认为是来自目标源服务器的响应。

RFC 6585 定义了一个扩展 HTTP 状态码(511),将信息传递回客户端软件,表明响应不是来自源服务器,并且未来可能会发生变化(例如,在执行任何闪屏页面登录后)。Squid-3.2 及更高版本可以配置为使用 `deny_info` 指令发送此扩展状态码和模板闪屏页面。

:information_source: 版本低于 3.2 的 Squid 无法发送扩展状态码。对于旧版本 Squid,您应该在 `deny_info` 指令中使用重定向 URL。 |

🔗 Squid 配置文件 - 简单示例

注意:以下示例中

Squid-3.2 及更高版本(会话助手重命名,以及带闪屏模板的 511 状态码)

# mind the wrap. this is one line:
external_acl_type splash_page ttl=60 concurrency=100 %SRC /usr/local/sbin/squid/ext_session_acl -t 7200 -b /var/lib/squid/session.db

acl existing_users external splash_page

deny_info 511:/etc/squid/splash.html existing_users

http_access deny !existing_users

🔗 Squid 配置文件 - 主动模式

您可能会发现使用上面的示例时,闪屏页面并不总是显示给用户。这是因为用户计算机上的其他进程(例如自动安全更新)会重置会话计数器,因此是那个进程而不是用户的浏览接收了闪屏。

以下配置示例添加了一个 `url_regex` 规则,强制用户在会话重置之前浏览到某个特定网站。此示例适用于 Squid-3.2 及更高版本,但可以适应早期版本。

# Set up the session helper in active mode. Mind the wrap - this is one line:
external_acl_type session concurrency=100 ttl=3 %SRC /usr/lib/squid3/ext_session_acl -a -T 10800 -b /var/lib/squid/session/

# Pass the LOGIN command to the session helper with this ACL
acl session_login external session LOGIN

# Normal session ACL as per simple example
acl session_is_active external session

# ACL to match URL
acl clicked_login_url url_regex -i a-url-that-must-match$

# First check for the login URL. If present, login session
http_access allow clicked_login_url session_login

# If we get here, URL not present, so renew session or deny request.
http_access deny !session_is_active

# Deny page to display
deny_info 511:/etc/squid/splash.html session_is_active

🔗 配置调整

:information_source: 更多信息请参阅 ext_session_aclexternal_acl_typeacldeny_infohttp_access


⚠️ Disclaimer: Any example presented here is provided "as-is" with no support
or guarantee of suitability. If you have any further questions about
these examples please email the squid-users mailing list.

类别: ConfigExample

导航:站点搜索站点页面分类🔼 向上