#author("2025-02-11T13:57:35+09:00","","") #author("2025-02-11T14:00:28+09:00","","") [[Linuxめも]] 通常のHTTPアクセスとは思えない悪意のあるものは拒否しましょう。~ 接続元がイケてない場合はわかりやすいUSER_AGENTである場合があります。 .htaccess ファイルに以下のように記述することで実現することができます。 USER_AGENT が Wget ではじまるものを拒否する場合。 SetEnvIf User-Agent "^Wget" DENY_AGENT order allow,deny allow from all deny from env=DENY_AGENT *VirtualHostで共通の設定を使用したい場合 [#n12db2ff] deny-list.conf ファイルを作成する -User-Agentに特定の文字列を含む場合拒否 -特定のIPアドレス 192.168.0.1 を拒否 -特定のIPアドレス 192.168.1.0 から 192.168.1.255 を拒否 SetEnvIf User-Agent "SemrushBot" deny_bot SetEnvIf User-Agent "BLEXBot" deny_bot SetEnvIf User-Agent "DomainCrawler" deny_bot SetEnvIf User-Agent "Bytespider" deny_bot SetEnvIf User-Agent "ClaudeBot" deny_bot SetEnvIf User-Agent "ImagesiftBot" deny_bot SetEnvIf User-Agent "DataForSeoBot" deny_bot <RequireAll> Require all granted Require not env deny_bot Require not ip 192.168.0.1 Require not ip 192.168.1.0/24 </RequireAll> VirtualHostの設定から deny-list.conf を Include する <VirtualHost *:443> ServerName sv1.example.com:443 DocumentRoot "/home/sv1/public_html" SSLEngine on SSLHonorCipherOrder on Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile /etc/letsencrypt/live/sv1.example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/sv1.example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/sv1.example.com/chain.pem <Directory "/home/sv1/public_html"> Options FollowSymLinks AllowOverride ALL # Require all granted Include /usr/local/apache2/conf/extra/deny-list.conf </Directory> ErrorLog "logs/sv1_error_log" CustomLog "logs/sv1_access_log" combined </VirtualHost> 設定が有効になっているか確認 curl -A "test" -I https://sv1.example.com/ HTTP/1.1 200 OK curl -A "SemrushBot" -I https://sv1.example.com/ HTTP/1.1 403 Forbidden *robots.txtで制御する [#z4355d79] 受け入れるボットはrobots.txtで頻度を指示 User-agent: bingbot Crawl-delay: 10 User-agent: * Crawl-delay: 5 VirtualHostの設定で一つのファイルを使いまわしたい場合はAliasを使う robots.txt は /home/common/public_html/robots.txt に設置した場合 <VirtualHost *:443> ServerName example.com:443 DocumentRoot "/home/example/public_html" Alias /robots.txt /home/common/public_html/robots.txt </VirtualHost>