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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kenichiro MATOHARA
July 09, 2022
Technology
390
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
72
念願のNDLOCR-Lite を試す
matoken
0
86
Nextcloud と互換性のある軽量WebDAV server のKaraDAV を試す
matoken
0
55
ActivityPub Server の snac その3
matoken
0
60
ActivityPub Server の snac その2
matoken
0
42
端末録画再生共有アプリ asciinema 3.0 リリース
matoken
0
74
アナウンス向けにミニマリスト向け ActivityPub Server の snac を利用
matoken
0
100
最近のNitterやX(old Twitter)関連 2025.09
matoken
0
86
ポータブルで色々なプロトコルに対応したファイルサーバーのcopypartyを試す
matoken
0
140
Other Decks in Technology
See All in Technology
Platform engineering for developers, architects & the rest of us (AI agents)
danielbryantuk
0
190
関西に縁あるMicrosoft MVPsが語るCopilotの未来
kasada
0
1.2k
Terraformモジュールは、なぜ「魔境」化するのか
hayama17
1
210
ABEMA の Datadog × OTel 基盤、 中から見るか? 外から見るか?
tetsuya28
0
110
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
Dynamic Workersについて
yusukebe
2
610
価格.comをAI駆動で全面刷新する ー 30年分の技術的負債を返し、次の30年の土台をつくる ー / AI Engineering Summit Tokyo 2026
tkyowa
50
54k
ブロックチェーン / Blockchain
ks91
PRO
0
110
探して_入れて_作って_使う_Agent_Skills___LT.pdf
peintangos
2
170
GoとSIMDとWasmの今。
askua
3
510
「気づいたら仕事が終わっている」バクラクAIエージェント本番運用の裏側 / layerx-bakuraku-aie2026
yuya4
19
11k
新規ゲーム開発におけるAI駆動開発のリアル
202409e2
0
2.7k
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
310
How to make the Groovebox
asonas
2
2.2k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Accessibility Awareness
sabderemane
1
130
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Context Engineering - Making Every Token Count
addyosmani
9
940
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Building Adaptive Systems
keathley
44
3k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
150
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
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