Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Webサーバが死んだので503だけを返す(Lighttpd/Apache httpd)
Search
Kenichiro MATOHARA
July 09, 2022
Technology
400
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Webサーバが死んだので503だけを返す(Lighttpd/Apache httpd)
https://gitlab.com/matoken/koedolug-2022.07
Kenichiro MATOHARA
July 09, 2022
More Decks by Kenichiro MATOHARA
See All by Kenichiro MATOHARA
今更LLMを触り始める(ローカルLLM bonsai)
matoken
0
97
念願のNDLOCR-Lite を試す
matoken
0
94
Nextcloud と互換性のある軽量WebDAV server のKaraDAV を試す
matoken
0
72
ActivityPub Server の snac その3
matoken
0
69
ActivityPub Server の snac その2
matoken
0
48
端末録画再生共有アプリ asciinema 3.0 リリース
matoken
0
85
アナウンス向けにミニマリスト向け ActivityPub Server の snac を利用
matoken
0
120
最近のNitterやX(old Twitter)関連 2025.09
matoken
0
94
ポータブルで色々なプロトコルに対応したファイルサーバーのcopypartyを試す
matoken
0
150
Other Decks in Technology
See All in Technology
最近評価が難しくなった
maroon8021
0
260
なぜ人は自分のプロジェクトを 「なんちゃってアジャイル」と 自嘲するのか
kozotaira
0
270
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
1k
デジタル・デザイン:次の50年を描く「進化する青写真」
y150saya
0
840
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
250
アカウントが増えてからでは遅い? ~ マルチアカウント統制の勘所 ~
kenichinakamura
0
210
ループエンジニアリングでE2Eテストを実践
noriyukitakei
0
320
ローカルLLMとLINE Botの組み合わせ その3 / LINE DC Generative AI Meetup #8
you
PRO
0
130
プロダクトだけじゃない、社内プロセスにおける自動化・省力化ノススメ
kakehashi
PRO
1
3.2k
しぶいSRE: サーバから見えない障害にどう向き合うか。ラストワンマイルのデバッグ実践 / Shibui SRE
kanny
12
5.5k
実装だけじゃない! CCA-F取得エンジニアが教えるClaude Code開発プロセス活用術
diggymo
2
490
Road to SRE NEXTの今までとこれから
hiroyaonoe
0
260
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
440
Being A Developer After 40
akosma
91
590k
WCS-LA-2024
lcolladotor
0
680
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
800
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.7k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
330
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
280
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Transcript
Webサーバが死ん Webサーバが死ん だので503だけを だので503だけを 返す 返す (Lighttpd/Apache (Lighttpd/Apache httpd) httpd)
1 / 27
南隅から参加(鹿児島の右下) 好きなLinuxディストリビューションはDebian お仕事募集 mailto:work@matohara.org Kenichiro Matohara(matoken) Kenichiro Matohara(matoken) https://matoken.org https://matoken.org
2 / 27
最近 最近 自宅サーバも死ぬ * Facebook復旧 https://www.facebookwkhpilnemxj7asaniu7vnjjbiltxjqh 3 / 27
今月壊れたもの 今月壊れたもの HP ProLiant MicroServer(初代) NASや自宅サーバとして利用していた Unboundも立てていたので名前解決ができなくなったりして困 った たぶん以前からS.M.A.R.T.から警告が出ていた /
のdiskが死ん だ ディスプレイとディスクが必要 4 / 27
外部向けWebサーバ 外部向けWebサーバ 外向けにもいくつかのサービスが動いていた 復旧目処がたっていない SBCのRaspberry Piでhttpdを起動してhttpステータスコード 503を返したい. 5 / 27
HTTPステータスコード HTTPステータスコード 通常は 200 OK だけど目にすることはない. 404 Not Found など
はよく見かけるのでは? 今回は 503 Service Unavailable にしてみた. 503 といっしょに Retry-After で復旧予定時間も出すといい のだけど未定なので無しで HTTP レスポンスステータスコード - HTTP | MDN 503 Service Unavailable - HTTP | MDN RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content 6 / 27
Raspberry Piの状況 Raspberry Piの状況 Raspberry Pi 3 model B Raspberry
Pi OS bullseye armhf導入 micro httpd起動中 7 / 27
httpdを変更 httpdを変更 micro httpdでの方法がよくわからない(VirtualDomain/すべて 503等)のでmicro httpdは止めて,Lighttpdに変更 $ sudo systemctl stop
micro-httpd $ sudo systemctl disable micro-httpd $ sudo apt install lighttpd lighttpd-mod-openssl 8 / 27
SSL証明書の入手 SSL証明書の入手 認証局には以前も利用していたLet’s Encryptを利用,専用の証明書 管理ツールのcertbotを導入して利用 $ sudo apt install certbot
$ sudo certbot certonly -d sub1.example.org $ sudo certbot certonly -d sub2.example.org $ sudo certbot certonly -d sub3.example.org : 9 / 27
Lighttpdのhttps設定 Lighttpdのhttps設定 lighttpd-enable-mod コマンドでLighttpdのsslモジュールと rewriteモジュールを有効に $ sudo lighttpd-enable-mod rewrite ssl
10 / 27
Lighttpdでのhttpsの設定 Lighttpdでのhttpsの設定 lighttpd/conf-enabled/10-ssl.conf を編集して証明書ファイル 指定 2つ目以降ののドメインを設定 Lighttpdを再読込して動作を確認 ssl.pemfile = "/etc/letsencrypt/live/sub1.example.org/fullchain.pem"
ssl.privkey = "/etc/letsencrypt/live/sub1.example.org/privkey.pem" $HTTP["host"] =~ "sub2.example.org"{ ssl.pemfile = "/etc/letsencrypt/live/sub2.example.org/fullchain.pem" ssl.privkey = "/etc/letsencrypt/live/sub2.example.org/privkey.pem" } $HTTP["host"] =~ "sub3.example.org"{ ssl.pemfile = "/etc/letsencrypt/live/sub3.example.org/fullchain.pem" ssl.privkey = "/etc/letsencrypt/live/sub3.example.org/privkey.pem" } : $ sudo systemctl lighttpd restart $ w3m https://sub1.example.org/ $ w3m https://sub2.example.org/ 11 / 27
HTTPステータスコード503を返 HTTPステータスコード503を返 す す HTTPステータスコード503を返すだけのcgi scriptを作成していつも それを返すように 12 / 27
cgiを有効に cgiを有効に lighttpd-enable-mod コマンドでLighttpdのcgiモジュールを有効 に /etc/lighttpd/conf-enabled/10-cgi.conf を以下のように修正 Lighttpdを再読込して動作を確認 $ sudo
lighttpd-enable-mod cgi $ grep -v ^# lighttpd/conf-enabled/10-cgi.conf | uniq server.modules += ( "mod_cgi" ) cgi.assign = ( ".cgi" => "/usr/bin/perl", ) $ sudo systemctl lighttpd restart $ echo "#!/usr/bin/perl print 'Content-Type: text/plain\n\nhello world.'" > /var/www/html/hello.cgi $ sudo chown www-data.www-data /var/www/html/hello.cgi $ sudo chmod 700 /var/www/html/hello.cgi $ w3m https://sub1.example.org/hello.cgi $ sudo rm /var/www/html/hello.cgi 13 / 27
503を返すcgiを用意 503を返すcgiを用意 HTTPステータスコード503を返す /var/www/html/503.cgi を用 意 #!/usr/bin/perl use strict; use
warnings; print "Status: 503 Service Unavailable\n"; print "Content-Type: text/html\n\n"; print <<END_OF_HTML; <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> <head> <meta charset="utf-8" /> <title>home.matoken.org</title> </head> <body> <p>Server is down.</p> </body> </html> END_OF_HTML 14 / 27
cgi scriptに権限を設定して動作確 cgi scriptに権限を設定して動作確 認 認 $ sudo chown www-data.www-data
/var/www/html/503.cgi $ sudo chmod 700 /var/www/html/503.cgi $ w3m -dump_head https://sub1.example.org/503.cgi | grep ^HTTP HTTP/1.0 503 Service Unavailable $ w3m https://sub1.example.org/503.cgi 15 / 27
Lighttpdですべてのアクセスに Lighttpdですべてのアクセスに 503を返すようにする 503を返すようにする /etc/lighttpd/lighttpd.conf ファイルに以下を追記 Lighttpdを再読込して動作を確認 $HTTP["url"] != "/503.cgi$"
{ url.rewrite = ( "" => "/503.cgi" ) } $ sudo systemctl lighttpd restart $ w3m https://sub1.example.org/hoge $ w3m https://sub2.example.org/fuga $ w3m http://sub1.example.org/hoge $ w3m http://sub2.example.org/fuga 16 / 27
ログ確認 ログ確認 /var/log/lighttpd/ を見ると error.log はあるけど access.log がない? lighttpd-enable-mod コマンドでLighttpdのaccesslogモジュー
ルを有効に $ sudo lighttpd-enable-mod accesslog $ sudo systemctl lighttpd restart 17 / 27
とりあえずok とりあえずok 案外アクセスある(9000/day) ほぼクロウラー 503を返してるのでリトライしてる? 復旧見込み時間を長めに設定して返すようにすると減るかも? 18 / 27
自宅回線が遅く 自宅回線が遅く もしかしてアクセスが多いせい? DNSを書き換えてアクセスの多いドメインを外のサーバに回してみる いつもはDown 8Mbps/Up 0.8Mbps程 $ speedtest-cli --simple
Ping: 639.861 ms Download: 0.44 Mbit/s Upload: 0.77 Mbit/s 19 / 27
外のサーバ 外のサーバ Debian bullseye amd64 Apache httpd 2.4.38 20 /
27
対象ドメインのSSL証明書取得 対象ドメインのSSL証明書取得 cpしてきてもいいと思う $ sudo certbot certonly -d sub1.example.org
21 / 27
503用のhtmlを用意 503用のhtmlを用意 $ sudo -u www-data mkdir /var/www/sub1.example.org $ sudo
-u www-data vi /var/www/sub1.example.org/503.html 22 / 27
対象ドメインの設定を作成 対象ドメインの設定を作成 `/etc/apache2/sites-enabled/090- sub1.example.org.conf apache httpd再起動 1 すべてを503として /503.html にリダイレクト
<VirtualHost *:80> ServerName sub1.example.org Redirect permanent / https://sub1.example.org/ </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName sub1.example.org ServerAdmin
[email protected]
DocumentRoot /var/www/sub1.example.org/ RedirectMatch 503 ^/(?!503\.html) ErrorDocument 503 /503.html ErrorLog ${APACHE_LOG_DIR}/error_sub1.example.org.log CustomLog ${APACHE_LOG_DIR}/access_sub1.example.org.log combined SSLCertificateFile /etc/letsencrypt/live/sub1.example.org/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/sub1.example.org/privkey.pem </VirtualHost> </IfModule> 1 $ sudo service apache2 restart 23 / 27
DNS書き換えを行い動作確認 DNS書き換えを行い動作確認 DNS書き換え前にhosts書き換えでテスト $ echo "192.0.2.5 sub1.example.org" | sudo tee
-a /etc/hosts $ w3m -dump_head head http://sub1.example.org/piyo | grep ^HTTP/ HTTP/1.1 503 Service Unavailable $ w3m -dump_extra head http://sub1.example.org/piyo | lv 24 / 27
余録)cowsay 余録)cowsay Lighttpdはcgiなのでなんとなくcowsayに喋ってもらうようにした (偶にecho-sd).しかしcgiから呼ぶと横幅がうまく取れなくなるよう (未解決) 25 / 27
まとめ まとめ 自宅サーバが起動しなくなったのでRaspberry Piで503を返すよ うにした. Lighttpdはrewrite+cgi Apache httpdはrewrite+html 自宅回線が遅くなったのは? 復旧のためにアルバイト探し中……
26 / 27
奥付 奥付 発表 未発表 発表者 利用ソフトウェア ライセンス 小江戸らぐ 7月のオフな集まり(第240回) Kenichiro
Matohara(matoken) Asciidoctor Reveal.js CC BY 4.0 27 / 27