close

抓最新版的 lighttpd source, 編譯, 跑簡單的 html ,

再嘗試 加入 CGI功能 , 測試也成功,

第三步, 加入認證和安全連線.

 

建立認證.

1. 修改 /usr/local/lighttpd/sbin/lighttpd.conf :

server.modules += ( "mod_auth" )

auth.debug = 0

auth.backend = "plain"

auth.backend.plain.userfile = "/usr/local/lighttpd/auth/.auth"

 

第一行加入 authentication module,

第二行拿掉 debug

第三行決定使用 plain authentication,

為什麼不用 digest ? 若要使用 digest, 必須用到 apache 的 htdigest 指令, 或是使用 hash 和 md5 來建立認證.

第四行就是指定 plain 加密的檔案存取路徑.

 

2. 新增/修改加密檔案 ->  /usr/local/lighttpd/auth/.auth

加上一行:

admin:pass

 

admin 是帳號, pass 是對應到的密碼.

 

3. 回到 /usr/local/lighttpd/sbin/lighttpd.conf 再加上:

auth.require = ("/"=>(

"method"=>"basic"

"realm"=>"Please input your authentication info"

"require"=>"user=admin"

)

)

 

先指定需要用認證保護的路徑, 我懶, 直接擺根目錄.

method 就是 basic, 

realm 代表網頁顯示輸入帳密的資訊,

require 指定作用的帳號, 因為剛剛在  /usr/local/lighttpd/auth/.auth 輸入的帳號是 admin,

所以這裡就放 admin.

 

4. browser 連網頁, 出線要輸入帳號密碼的訊息, 成功 !

************************************

SSL 連線:

再度回到 /usr/local/lighttpd/

mkdir ssl; cd ssl

1. 建立 private key

openssl genrsa -out privkey.pem 2048

2. 產生數位憑證

先做出 "請求"

openssl req -new -key privkey.pem -out cert.csr

接著會有一堆東東要輸入 ... 不過不重要.

完成以後, 再用 "請求" 去生成憑證.

因為測試用, 所以自己生成憑證即可.

openssl req -new -x509 -days 3650 -key privkey.pem -out cacert.pem

接著也是要輸入一堆東東 ... 跟剛剛一樣.

3.  cat privkey.pem cacert.pem > lighttpd.pem

把憑證和key弄一塊.

4. 編輯 /usr/local/lighttpd/sbin/lighttpd.conf 

$SERVER["socket"] == "xxx.xxx.xxx.xxx:443" {
server.document-root="/usr/local/lighttpd/www/"
ssl.engine = "enable"
ssl.pemfile = "/usr/local/lighttpd/ssl/lighttpd.pem"
}

5. 測試: https://xxx.xxx.xxx.xxx/ 

成功 !

 

參考:

1. lighttpd 的認證分類

http://redmine.lighttpd.net/projects/1/wiki/Docs_ModAuth

2. plain password

http://stackoverflow.com/questions/2171922/lighttpd-how-to-password-protect-urls-matching-regex

http://2skies.com/docs/basic_http_authentication_with_lighttpd

3. plain & digest

http://kunaljain.wordpress.com/2007/08/08/lighttpd-setup-password-protected-directoriesmod_auth/

4. digest

http://www.weithenn.org/cgi-bin/wiki.pl?LigHttpd-%E8%BC%95%E9%87%8F%E7%B4%9A_Web_Server#Heading9

5. ssl

http://ching119.blogspot.tw/2012/04/lighttpd-ssl.html

http://linux-guys.blogspot.tw/2010/12/lighttpd-httpsssl.html

http://www.cyberciti.biz/tips/howto-lighttpd-create-self-signed-ssl-certificates.html

http://www.cyberciti.biz/tips/how-to-install-ssl-lighttpd-https-configuration.html

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 kk 的頭像
    kk

    kk

    kk 發表在 痞客邦 留言(0) 人氣()