Apache2在Ubuntu上的防盗篡改实践
术语澄清与目标
一、防盗链配置 mod_rewrite
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html
RewriteEngine On
# 允许自家域名与空Referer
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^$
# 保护常见静态资源
RewriteRule \.(jpg|jpeg|png|gif|webp|svg|css|js|pdf|zip|rar)$ - [F,L]
<Directory /var/www/html>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
二、防篡改组合方案
三、快速验证与运维
四、注意事项