Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Webサーバが死んだので503だけを返す(Lighttpd/Apache httpd)
Search
Kenichiro MATOHARA
July 09, 2022
Technology
410
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
ファイル共有ソフトウェアのOpenCloud 8.0.0を試す
matoken
0
14
ターミナルグラフィックウェブブラウザ!?
matoken
0
55
軽量ウェブブラウザDilloのPlugin
matoken
0
56
今更LLMを触り始める(ローカルLLM bonsai)
matoken
0
220
念願のNDLOCR-Lite を試す
matoken
0
130
Nextcloud と互換性のある軽量WebDAV server のKaraDAV を試す
matoken
0
150
ActivityPub Server の snac その3
matoken
0
95
ActivityPub Server の snac その2
matoken
0
65
端末録画再生共有アプリ asciinema 3.0 リリース
matoken
0
110
Other Decks in Technology
See All in Technology
メルペイ 会計システム概要と歴史
mewuto
0
200
自作バイナリを動かす「入口」8選
puhitaku
1
1.2k
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
530
20260930_Gemma4_Hands-on
tsho
0
240
初対面のメンバーがチームを組み、Claude Codeでゼロからサービスをリリース
mkdev10
1
110
Google Cloud Next Tokyo 26登壇時のスクリプト
recruitengineers
PRO
0
210
オブザーバビリティを高める AI エージェント体験を考える / Designing AI Agent Experiences That Enhance Observability
aoto
PRO
2
320
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
290
自律型 AI をセキュアに実装!Gemini と MIG で作る動的コード実行環境
recruitengineers
PRO
1
230
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
170
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
170
全PRの83%が AIレビューだけでマージできるようになった開発組織は その後どうなったか @2026/10
athug
0
130
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
350
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
310
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
260
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.3k
Navigating Team Friction
lara
192
16k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Docker and Python
trallard
47
4.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Statistics for Hackers
jakevdp
799
230k
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