Nitter – matoken's blog https://matoken.org/blog Is there no plan B? Fri, 11 Mar 2022 14:25:53 +0000 ja hourly 1 https://wordpress.org/?v=6.9.4 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg Nitter – matoken's blog https://matoken.org/blog 32 32 nitterのアップグレードメモ(2022-03) https://matoken.org/blog/2022/03/11/nitter-upgrade-note2022-03/ https://matoken.org/blog/2022/03/11/nitter-upgrade-note2022-03/#respond Fri, 11 Mar 2022 14:24:21 +0000 http://matoken.org/blog/?p=3524

Nitterをセルフホストしています.

最新に追従しているのですが,以前と少し手順が変わっているので上の記事に補足する形でメモしておきます.

sourceの更新とビルド準備
$ sudo su - nitter	(1)
$ cd ~/nitter	(2)
$ git pull	(3)
$ pandoc ./README.md -o - | w3m -T text/htm
$ export PATH=~/nim-1.6.4/bin:${PATH}	(4)
$ echo $PATH
/home/nitter/nim-1.6.4/bin:/home/nitter/bin:/usr/local/bin:/usr/bin:/bin
$ nim -v	(5)
Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-09
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 7994556f3804c217035c44b453a3feec64405758
active boot switches: -d:release
  1. nitter アカウントに変更
  2. nitter のsourceディレクトリへ移動
  3. nitter のsourceをpull
  4. 一時的に nim の PATH を通す
  5. nim が使いたいバージョンに向いているのを確認
nitterのbuildと設定
$ nimble build -d:release
$ nimble scss
$ vi public/md/about.md	(1)
$ nimble md	(2)
$ diff -u ./nitter.example.conf ./nitter.conf	(3)
--- ./nitter.example.conf       2022-02-15 00:03:01.628730418 +0900
+++ ./nitter.conf       2022-03-11 22:53:41.944448701 +0900
@@ -1,11 +1,11 @@
 [Server]
-address = "0.0.0.0"
-port = 8080
-https = false  # disable to enable cookies when not using https
+address = "localhost"
+port = 8081
+https = true  # disable to enable cookies when not using https
 httpMaxConnections = 100
 staticDir = "./public"
 title = "nitter"
-hostname = "nitter.net"
+hostname = "nitter.matoken.org"

 [Cache]
 listMinutes = 240  # how long to cache list info (not the tweets, so keep it high)
@@ -25,6 +25,7 @@
 enableRSS = true  # set this to false to disable RSS feeds
 enableDebug = false  # enable request logs and debug endpoints
 proxy = ""  # http/https url, SOCKS proxies are not supported
+#proxy = "http://153.121.44.87:8888"  # http/https url, SOCKS proxies are not supported
 proxyAuth = ""
 tokenCount = 10
 # minimum amount of usable tokens. tokens are used to authorize API requests,
@@ -42,4 +43,4 @@
 replaceInstagram = ""
 proxyVideos = true
 hlsPlayback = false
-infiniteScroll = false
+infiniteScroll = true
$ vi ./nitter.conf
$ exit
$ sudo service nitter restart
  1. 必要なら ${NITTER_URL}/about の元になる about.md を編集
  2. markdownをhtmlに変換(about.md以外のファイルをおいても変換されるが表示は出来ない?)
  3. nitter.conf を確認して設定の増減があったら追従する

以前はなかったabout.mdはこのインスタンスは誰が管理していますと書いておくのもいいかなと思います.
設定のproxyを使うと,Twitterにアクセス制限されたときに簡単に切り替えることができそうです.

環境
$ git -C ~nitter/nitter log -1
commit 2dc91f8453ce904d1b07a933e8a1dc970d788c41 (HEAD -> master, origin/master, origin/HEAD)
Merge: ecb6fe4 9b97ddc
Author: Zed <zedeus@pm.me>
Date:   Thu Mar 10 16:46:14 2022 +0100

    Merge pull request #571 from jackyzy823/fix-listmember

     Fix list members not displaying
$ w3m -dump http://localhost:8081/about | grep ^Version\
Version 2022.03.10-2dc91f8
$ nim -v
Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-09
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 7994556f3804c217035c44b453a3feec64405758
active boot switches: -d:release
$ dpkg-query -W apache2 redis* libsass-dev certbot
apache2 2.4.38-3+deb10u7
certbot 0.31.0-1+deb10u1
libsass-dev:amd64       3.5.5-4
redis-server    5:5.0.14-1+deb10u2
redis-tools     5:5.0.14-1+deb10u2
 lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/03/11/nitter-upgrade-note2022-03/feed/ 0
Nitterにrobots.txtを設定(Apache httpdのreverse proxy環境でAlias設定) https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/ https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/#comments Sun, 30 May 2021 22:39:20 +0000 http://matoken.org/blog/?p=3253

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

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

まずは適当な robots.txtNitter の 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
]]>
https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/feed/ 1
軽量TwitterフロントエンドのNitterをセルフホスト https://matoken.org/blog/2021/02/17/self-hosting-the-lightweight-twitter-front-end-nitter/ https://matoken.org/blog/2021/02/17/self-hosting-the-lightweight-twitter-front-end-nitter/#comments Wed, 17 Feb 2021 13:34:23 +0000 http://matoken.org/blog/?p=3007

NitterというTwitterのフロントエンドがあります.最近はTwitterが重くてなにか検索しようと思っても待ち長かったり画像読み込み失敗したりといったこともよくあります(PCのスペックと回線が細いせいも大きいですが).軽量ブラウザを使ったりもしてみましたがそうすると見た目や使い勝手がいまいち.

そして現在そういった軽量ブラウザは利用もできなくなりました.

This browser is no longer supported.
Please switch to a supported browser to continue using twitter.com. You can see a list of supported browsers in our Help Center.

そこで Nitter を試してみたところ軽くていい感じです.

現在ログイン機能はないので,投稿や非公開Tweetや非公開リストなどは使えませんが,イベントのハッシュタグを追ったり,過去のtweetを検索といったことをするのに便利です.

RSS形式での出力にも対応しています.

軽量で便利なのでロカールマシンでNitterを動かして外にURLを共有するときは https://nitter.net/ を利用していました.

という話を以前オープンソースカンファレンス2020福岡内の鹿児島らぐのコマで発表しました.

しかし,最近は https://nitter.net/ がTwitterの制限に掛かって利用できないことが多くなってきました.なので自分のVPS上にホストしてみました.

Note
同じ手順で Raspberry Pi OS buster armhf や Debian sid(nimはDebinaパッケージのもの利用)でも動作しました.

Nitterのインストール環境の用意

Nitterが依存している Redislibsass を導入しておきます.

$ sudo apt install redis-server libsass-dev

Nitterを専用アカウントで動かしたいので nitter ユーザ,グループを作ってそのユーザで操作します.

$ sudo groupadd nitter (1)
$ sudo useradd -m -g nitter nitter (2)
$ sudo -iu nitter (3)
  1. nitter グループを作成
  2. nitter ユーザを作成
  3. nitter ユーザのシェルを開く

nimの用意

Nitterはnim-langで出来ています.Nitterのコンパイルにはnim 1.2.0以上が必要ですが,Debian busterのパッケージ版のnimは 0.19.4 でコンパイル出来ません.buster-backports も 1.0.4-1~bpo10+1 と対応していません.(bullseyeは1.4.2)

$ nimble build -d:release
  Verifying dependencies for nitter@0.1.0
       Tip: 2 messages have been suppressed, use --verbose to show them.
     Error: Unsatisfied dependency: nim (>= 1.2.0)
$ dpkg-query -W nim
nim     0.19.4-1

とりあえずnimの公式サイトのバイナリを利用してコンパイルすることにします.

$ wget https://nim-lang.org/download/nim-1.4.2-linux_x64.tar.xz \
https://nim-lang.org/download/nim-1.4.2-linux_x64.tar.xz.sha256 (1)
$ sha256sum -c ./nim-1.4.2-linux_x64.tar.xz.sha256 (2)
nim-1.4.2-linux_x64.tar.xz: OK
$ tar tvf nim-1.4.2-linux_x64.tar.xz | lv (3)
$ tar xvf nim-1.4.2-linux_x64.tar.xz (4)
  1. nimのバイナリをダウンロード
  2. hash確認
  3. アーカイブ確認
  4. アーカイブ展開

Nitterのコンパイル

Nitterのsourceをcloneしてさっきダウンロードして展開したnimでコンパイルします.

$ git clone https://github.com/zedeus/nitter
$ cd nitter
$ PATH=~/nim-1.4.2/bin:$PATH nimble build -d:release
$ PATH=~/nim-1.4.2/bin:$PATH nimble scss
$ mkdir ./tmp

Redis が起動しているのを確認して nitter を起動してみます.この状態で 8080 ポートにアクセスして Nitter が利用できるのを確認します.ポート番号などは nitter.conf で変更できます.

$ ps -ef|grep -i redis (1)
redis    11786     1  0 Feb11 ?        00:15:28 /usr/bin/redis-server 127.0.0.1:6379
$ ./nitter & (2)
$ w3m http://localhost:8080/ (3)
$ kill %1 (4)
$ exit (5)
  1. Redisが動いているのを確認
  2. Nitterを起動
  3. Nitterの動作を確認
  4. Nitterを終了
  5. nitter アカウントから抜ける

Nitterの起動設定

次にNitterに起動設定を行います.Systemd環境なので以下のようなサービスファイルを用意しました.

/etc/systemd/system/nitter.service
[Unit]
Description=Nitter (An alternative Twitter front-end)
After=syslog.target
After=network.target

[Service]
Type=simple

# set user and group
User=nitter
Group=nitter

# configure location
WorkingDirectory=/home/nitter/nitter
ExecStart=/home/nitter/nitter/nitter

Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

サービスを有効にしてNitterを起動します.

$ sudo systemctl enable --now nitter.service
$ systemctl status nitter
● nitter.service - Nitter (An alternative Twitter front-end)
   Loaded: loaded (/etc/systemd/system/nitter.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2021-02-17 01:13:07 JST; 34s ago
 Main PID: 19702 (nitter)
    Tasks: 1 (limit: 4696)
   Memory: 3.6M
   CGroup: /system.slice/nitter.service
           └─19702 /home/nitter/nitter/nitter
$ w3m http://localhost:8080/

外に公開せず,ローカルで動作させる場合はここまでの手順でOKです.

ドメインとSSL証明書の用意

※この手順はローカルで動かす場合は必要ありません.

今回はサブドメインを用意しました.DNSを設定して nitter.matoken.org を用意しました.設定ミスしたときにリカバリしやすいようにTTlを短く設定してうまく行ったらいつもの長さにします.

証明書はcertbotを使いLet’s encryptで作成しました.

$ sudo certbot certonly -d nitter.matoken.org

apache httpdの用意

※この手順はローカルで動かす場合は必要ありません.

Nitterをそのまま外に公開するのはセキュリティ的に良くないということで,apache httpdでhttpdの処理をしてNitterの8080に転送するようにしました.

Nitter用のapache httpd設定ファイルを用意します.

/etc/apache2/sites-available/nitter.matoken.org.conf
<VirtualHost *:80>
        ServerName nitter.matoken.org
        Redirect permanent / https://nitter.matoken.org/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName nitter.matoken.org
        ServerAdmin webmaster@matoken.org

        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>

        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/ nocanon
        ProxyPassReverse / http://127.0.0.1:8080/
        AllowEncodedSlashes On

        ErrorLog ${APACHE_LOG_DIR}/error.nitter.matoken.org.log
        CustomLog ${APACHE_LOG_DIR}/access.nitter.matoken.org.log combined

        SSLCertificateFile /etc/letsencrypt/live/nitter.matoken.org/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/nitter.matoken.org/privkey.pem

</VirtualHost>
</IfModule>

設定を有効にしてテスト後反映します.

$ sudo a2ensite nitter.matoken.org.conf (1)
$ sudo apache2ctl configtest (2)
$ sudo systemctl reload apache2 (3)
  1. 設定ファイルを有効にする
  2. 設定ファイルのテスト
  3. apache httpdの設定反映

この状態で http://nitter.matoken.org/ 及び https://nitter.matoken.org/ にアクセスしてみて Nitter が利用できたらOKです.

とりあえず一般公開しておきますが,今の https://nitter.net みたいにアクセス制限がしょっちゅうかかるようになったら制限するかもしれません.

環境

$ git -C ~nitter/nitter log -1
commit f392b6ca37e66c7c759aa98db23e0bdc62b39c3d (HEAD -> master, origin/master, origin/HEAD)
Author: Lukas Winkler <github@lw1.at>
Date:   Sun Feb 14 12:49:09 2021 +0100

    run optipng -o 9 on all images (#337)
$ dpkg-query -W apache2 redis* libsass-dev certbot
apache2 2.4.38-3+deb10u4
certbot 0.31.0-1+deb10u1
libsass-dev:amd64       3.5.5-4
redis-server    5:5.0.3-4+deb10u2
redis-tools     5:5.0.3-4+deb10u2
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/02/17/self-hosting-the-lightweight-twitter-front-end-nitter/feed/ 3