在Caddy2中为站点添加真实IP标头,以便捷获取客户端IP。添加自定义标头,以满足不同业务的需求。
真实IP#
此配置可以在使用了Cloudflare CDN的情况下获取访客真实IP
1
2
3
4
5
6
7
8
9
|
example.com {
reverse_proxy {
to 0.0.0.0:8080
header_up X-Real-IP {remote_host}
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
header_up X-Forwarded-Proto {http.request.header.CF-Visitor}
}
}
|
HSTS#
此配置会通告浏览器在接下来的1年内使用HTTPS访问该网页
1
2
3
4
5
6
|
example.com {
reverse_proxy {
to 0.0.0.0:8080
header_up Strict-Transport-Security "max-age=31536000;"
}
}
|
禁止嗅探#
防止浏览器对响应的内容类型进行自动推测,增加网站安全性
1
2
3
4
5
6
|
example.com {
reverse_proxy {
to 0.0.0.0:8080
header_up X-Content-Type-Options "nosniff"
}
}
|
移除X-Powered-By和Server标头#
移除X-Powered-By标头,防止后端技术泄露,避免针对性打击
1
2
3
4
5
6
7
|
example.com {
reverse_proxy {
to 0.0.0.0:8080
header_down -X-Powered-By
header_down -Server
}
}
|
禁止搜索引擎索引#
禁止搜索引擎爬虫对网页进行索引
1
2
3
4
5
6
|
example.com {
reverse_proxy {
to 0.0.0.0:8080
header_up X-Robots-Tag "noindex, nofollow"
}
}
|