技術

nginxにX-Robots-Tagを設定する

投稿日:

こんにちは

検索結果にページが表示されないようにするために
metaタグには

<meta name="robots" content="noindex" />

というものがありますが
実は、HTTPヘッダーでも指定することが可能です。

今回はnginxに設定してみたいと思います。
/etc/nginx/nginx.confか
/etc/nginx/sites-available/default
のどちらかお好きな方で大丈夫です。

locationにX-Robots-Tagを書きます。

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# 下記を追加
add_header  X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
}

設定したらnginxを再起動します。

確認したいときは下記のサイトにURLを入力します。
https://headers.cloxy.net/

レスポンスの中に

X-Robots-Tag: noindex, nofollow, nosnippet, noarchive

があれば設定完了です。

参考URLはこちら
robots メタタグと X-Robots-Tag HTTP ヘッダーの仕様
Nginx rule to add x-robots-tag header

-技術

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事

go

【Golang】package strconvのintSize = 32 << (∧uint(0) >> 63)は何をしているのか

こんにちは Goのstrconvのパッケージを読んでたらintSizeというもの …

[Angular] @NgModuleをざっくりと

どうも中田です。 最近社内でAngularの波が起こってるので そのビッグウェー …

no image

[Rails]link_toをhelperから使う

こんばんは Railsでviewを作成している時に、helperからlink_t …

[Bitbucket] fatal: Could not read from remote repository.

どうも中田です こないだリモートリポジトリにPushできないんすけど〜という話を …

[Xcode] SDK Version Issue – This app was built with the iOS 12.0 SDK. Starting March 2019, all iOS apps submitted to the App Store must be built with the iOS 12.1 SDK or later, included in Xcode 10.1 or later.

こんにちは。たなかです。 2019年、ブログ初更新になります。今年もよろしくお願 …