使用CDN网站加速后 caddy日志里面IP就都变成CDN的了。下面介绍一下获取访客真实IP地址方法。
1、安装 real IP 插件,这里使用的是caddy官方一键安装脚本。(就是 http.realip 这个插件。)
curl https://getcaddy.com | bash -s personal dns,http.cache,http.filter,http.git,http.ipfilter,http.realip
2、更改权限
chown root:root /usr/local/bin/caddy && chmod 755 /usr/local/bin/caddy
3、修改配置文件(一般是“/etc/caddy/Caddyfile
”)。关键代码为下面 realip 部分,其他的可以根据自己的需要更改。
aaa.com {
root /var/www/typecho
log / /var/log/caddy/aaa_com.log "{remote} - {user} [{when}] {when_unix} \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\""
tls mail@gmail.com
gzip
header / Strict-Transport-Security "max-age=31536000"
fastcgi / /run/php/php7.1-fpm.sock php
rewrite {
if {path} not_match ^\/admin
to {path} {path}/ /index.php?{query}
}
realip {
from 0.0.0.0/0
}
}
4、重新启动 caddy
systemctl restart caddy
5、现在就可以在Caddy的log处(例:/var/log/caddy/aaa_com.log
)的第一列显示访客的真实IP了。