0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Wordpress(Kusanagi)でクロール拒否

0
Last updated at Posted at 2026-04-21

AamazonやらMetaやら容赦ないクロールでの攻撃でサーバーの不可がすごいのでその対応。

前提環境

Wordpress(Kusanagi)
Nginx

1.meta robotsの設定を行う

適切にmeta robotsの設定を行い、クロールの制限を行いましょう。
Wordpress5.7.0以降ではwp_robotsでrobotsを変更できるので、プラグインを使わずfunction.phpで対応
All in One SEO等のプラグインでrobotsの設定を行っても構いません。

今回は「/xxxx/?date=」のクエリパラメーターのdateの値を変更して、大量にアクセスが来てたので、
そのページをnoindex,nofollowに設定することにしました。

下記をfunction.phpに記載。

/** 
 * meta robotsの変更
 */
function meta_robots_edit( array $robots ) {
	if ( is_attachment() || is_author() || is_date() || is_page([11, 15])) {
		$robots['noindex'] = true;
		$robots['nofollow'] = true;
		$robots['max-image-preview'] = false;
	}
	return $robots;
}
add_filter( 'wp_robots', 'meta_robots_edit' );

以下のページのrobotsをnoindex,nofollowに設定しています。

  • 添付ファイルページ:is_attachment()
  • 著者アーカイブページ:is_author()
  • 日付ベースのアーカイブページ:is_date()
  • 固定ページ:is_page() ※()内の数字は固定ページのページIDを指定しています

2.robots.txtの設定を行う

各環境に合うようにrobots.txtでクロールのアクセスを除外するように設定。
必ずしもクロールする側がこれに従うわけではないようなので注意。

robots.txtは下記の手順で設定できます。

2-1. robots.txtを作成
wordpressのDocumentRoot配下にrobots.txtがなければ作成
Kusanagiだと下記位置。
/home/kusanagi/xxxxxx/DocumentRoot/

2-2. robots.txtに下記を追記

 User-agent: Amazonbot
 Disallow: /
 
 User-agent: ClaudeBot
 Crawl-delay: 3
 
 User-agent: Meta-ExternalAgent
 Disallow: /
 
 User-agent: Meta-ExternalFetcher
 Disallow: /
 
 Sitemap: https://oge.pleeds.com/wp-sitemap.xml

ご自身の環境に合わせてパスを変更したりしてクロールを拒否してください。
上記は

  • Amazonbot、Meta-ExternalAgent、Meta-ExternalFetcherを拒否
  • ClaudeBotは、クロールする際に3秒待機して次のページをクロールしてと指示

3.nginxの設定を行う

もうクロールからのアクセスはページを表示しなくていい、403ページでOKという場合はnginxで拒否。

KusanagiのNginxの設定ファイルは下記にあります。
/etc/opt/kusanagi/nginx

今回は /etc/opt/kusanagi/nginx/conf.d/xxxxxxxxxxxx.wp.incのファイルに下記を追加。

xxxxxxxxxxxxxの部分は各自のインストールしたWordpressのコード。
/home/kusanagi/配下にあるディレクトリ名になります。

location ~* /\. {の上に追記してます。

location / {
    set $is_bot 0;
    if ($http_user_agent ~ (Amazonbot|meta-externalagent|other_bot_user_agent)){
        set $is_bot 1;
    }
    if ($is_bot = 1) {
        error_page 403 /static/bot_403.txt;
        return 403;
    }
    try_files $uri $uri/ /index.php?$args;
}

設定変更後はNginxのチェックと再起動。

kusanagi nginx --test
kusanagi nginx --reload

まとめ

各自適切にクロール対策を行ってください。上記は一例です。
クロールのアクセス数が短時間に大量にくるのでサーバーが重くなり困りますが、
全てはじいてしまうとサイトを認識してもらえない可能性もあります。
部分的に拒否したり、クロール頻度を指定したりして、上手にかわしていきましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?