basic authenticate in h2o
H2Oでベーシック認証したい場合は以下のようにします1
paths:
"/":
mruby.handler: |
require "htpasswd.rb"
Htpasswd.new("/etc/h2o/.htpasswd", "realm-name")
また、 .htpasswd
で plain フォーマットはサポートされていません。
failed to validate password using file:/etc/h2o/.htpasswd:crypt-style password hash is not supported
.htpasswd
を手動で作成したい場合は以下の方法でできます2
require "digest/sha1"
require "base64"
open("/etc/h2o/.htpasswd", "w") do |w|
w.write("user:{SHA}#{Base64.encode64(Digest::SHA1.digest("password"))}")
end