技術

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 を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事

[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年、ブログ初更新になります。今年もよろしくお願 …

no image

ActiveRecord::Relationのklassメソッドでmodelを取得できる。

こんにちは。コーテッグのこやまです。 モデルに対してallやwhereメソッドを …

docomo雑談対話APIを使って会話BOTを作りました。(LINE BOT + Heroku + Rails + docomo雑談API)

こんばんは 前回、LINE BOTを無料で試してみました。heroku + Ra …

no image

[Rails]link_toをhelperから使う

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

no image

こんにちは。コーテッグの小山です。 以前リアクティブフォームのHTML側の記述と …