Nitterにrobots.txtを設定(Apache httpdのreverse proxy環境でAlias設定)

以前軽量TwitterフロントエンドのNitter をセルフホストしました.

最近アクセスが増えていて少しサーバが重くなったり自分が使うときに調子が悪かったりしています.クローラなんかが多いようなのでこれを robots.txt で拒否すると大分アクセスが減るのではと思い設定してみました.

まずは適当な robots.txt 🏛️Nitter の Root に置いてみましたが,対応していないようでアクセスできません.
Nitter の前段に置いてある Apache2 httpd でAlias を設定すればと思ってApache httpd のNitter の設定の VirtualHost の中に以下の設定を追加してみました.

/etc/apache2/sites-available/nitter.matoken.org.conf
        Alias /robots.txt /home/nitter/robots.txt
        <Location "/robots.txt">
                Require all granted
        </Location>

追加したあと設定を確認して設定を再読込します.

$ sudo a2ensite nitter.matoken.org.conf
$ sudo apache2ctl configtest
$ sudo systemctl reload apache2

しかしこの状態で /robots.txt にアクセスするとhttp ステータスコード 404 が帰ってきてアクセスできません.Proxy の方が優先のようです.

検索してみると以下のpageを見つけました. ProxyPass! を指定して指定したURLをProxy で無視するようにできるようです.

ということでこのように設定してみました.

        Alias /robots.txt /home/nitter/robots.txt
        <Location "/robots.txt">
                ProxyPass !
                Require all granted
        </Location>

再度設定チェックして再読込すると動作しました :)

$ w3m -dump_head https://nitter.matoken.org/robots.txt
HTTP/1.1 200 OK
Date: Sun, 30 May 2021 15:26:17 GMT
Server: Apache/2.4.38 (Debian) OpenSSL/1.1.1d
Last-Modified: Mon, 12 Apr 2021 23:19:53 GMT
ETag: "32c8-5bfcec03dd840-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 2938
Connection: close
Content-Type: text/plain

1日ほど待ってからアクセスの変化を見てみようと思います.

環境
$ dpkg-query -W apache2
apache2 2.4.38-3+deb10u4
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64

One thought to “Nitterにrobots.txtを設定(Apache httpdのreverse proxy環境でAlias設定)”

コメントを残す

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

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)