在CentOS上配置Apache2防盗版(防盗链)主要有以下两种方法:
sudo yum install httpd。sudo systemctl start httpd,sudo systemctl enable httpd。/etc/httpd/conf/httpd.conf或/etc/httpd/conf.d/下新建如anti - hotlinking.conf文件,添加规则:
<Directory "/var/www/html">
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpg|jpeg|png|gif)$ - [F,L]
</Directory>
sudo systemctl restart httpd。/var/www/html),创建或编辑.htaccess文件。RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpg|jpeg|png|gif)$ - [F,L]
AllowOverride All)。sudo systemctl restart httpd。以上配置中,yourdomain.com需替换为实际域名,可根据需求调整允许的域名和文件类型。