Ȼ/07

Top / Ȼ / 07

Хӥ: web

web ФѰդƤߤ褦.
web ФȤˤ꤫ĺǤɤȤΤϸǤApache*1 Ǥ.
Apache Software Foundation*2dzȯƤ.
ȼä˽Ȥʤ꤬ webХץȤƤϡֹȤƤơ᤯ΤפΤȤΤ褤.

ѤΥ饤󥹳ǧ

ޤϤȤ⤫饤󥹤ǧ褦*3.

½

Apache Υ饤󥹤ɤΤ褦ʤΤĴ٤.

󥹥ȡ뤵Ƥʤå

˥󥹥ȡ뤵Ƥʤå. ޤ

 pkg_info -a | grep "Information for" | less

Ȥơ apache ʤߤ. ǰΰ١

 ps -axuww | less 

η̤򸫤ơweb server तäƤʤ(ưƤ httpd ʤɤʸ󤬸)/usr/local/etc/rc.d apache ʤɤ̵ǧ.

嵭Ƥޤå褦.
ΤĤ꤬ʤΤ˥󥹥ȡ뤵ƤȤ褦ʾϡǰΰ٤˰ö󥤥ȡ뤷褦*4.

󥹥ȡ뤹٤Сİ

ȤꤢǿСǤ褤褦˻פ줰餤礭ʥեȥȤ⤤ʤȤ⤢.
ǡ礶äѤǤ褤ΤǥСˤ㤤ɤʤΤĴ٤Ƥ.

½

ޤʬ apache ˤϸߤ 1.32.02.23ĤΥС󤬤.
ˤɤΤ褦ʰ㤤Τ礶äѤˤǤ褤ΤǤ٤.

󥹥ȡ

ơ󥹥ȡ ports Υ󥹥ȡǤ褤ĤȤ줬褤.
ǰΰ٤ ports ǿΤΤˤƤˤ褦*5.

ơ󥹥ȡ뤹С 2.2 ȤƤ.
Ūˤϡ

 cd /usr/ports
 portinstall www/apache22

Ȥ 2.2.6_2 󥹥ȡ뤵ϤǤ. ʬΤǤäԤȤ.

ư

ޤ OS ֡Ȼ apache ư褦ˤ褦. /etc/rc.conf

 apache22_enable="YES"

Ƚ񤭹.
ǰΰ٤˥֡ȤƤ.

ưå

ơǴ˵ư apache ư褦ˤʤäƤϤʤΤǡޤϵưƤ뤫ǧ褦.
Ūˤϡޤ

 ps -axuww | less

httpd ưƤΤǧơưƤʤФ firefox webbrowser

 http://localhost/

˥Ƥߤ褦. "It Works!" ʤɤɽФޤϵư OK .

ˡ³򸫤뤿

 cd /usr/local/www/apache22/cgi-bin
 chmod aog+x ./printenv

Ȥơץ cgi ưĤФƤ顤٤

 http://localhost/cgi-bin/printenv

³Ƥߤ褦. ³ȤδĶ狼뤳ȤƼ.

ʤޤä顤ǰΰ٤˰ʲΤ褦ˤƥץ cgi ưʤ褦ᤷƤ.

 cd /usr/local/www/apache22/cgi-bin
 chmod aog-x ./printenv

˼ư apache ư᤿ꤹˡ񤤤Ƥ.
ưǵưʤС

 /usr/local/etc/rc.d/apache22 start

Ȥưǻߤ᤿

 /usr/local/etc/rc.d/apache22 stop

ȤФ褤.

ơapache ̵˵ưƤ뤳ȤޤdzǧǤưǤä apache 褦.
ƺƤ webbrowser http://localhost ˥ơ apache ޤäƤ뤳Ȥǧ褦.

¤

apache ե /usr/local/etc/apache22 ʲ֤Ƥ.
ơ¤Ԥ.

ޤweb ФȤƤδե httpd.conf ǤΤǤԽ*6.

ѹΤϰʲǤ.

ServerAdmin
web ԤΥ᡼륢ɥ쥹. ץ뤬񤤤ƤΤǤ狼.
DocumentRoot
web Υ롼ȤȤưǥ쥯ȥ.
ǥեȤǤ /usr/local/www/apache22/data ȤʤäƤ뤬apache ΥСäƤꤷƤʤȤؤޤ٤ǤϤ뤬ƥ̤ǥեȤΤޤޤˤƤʤ褦ˤ褦.
ǡ˥ǥ쥯ȥ(㤨 /usr/local/web_dir/top ʤ*7 )ѰդƤ, 񤭴Ƥ.
϶Ūˤ
 DocumentRoot "/usr/local/www/apache22/data"
ȤԤ򤳤
 DocumentRoot "/usr/local/web_dir/top"
Ƚ뤳Ȥˤʤ.
ޤDocumentRoot Ȥ˴ؤʬ <Directory "/usr/local/www/apache22/data">ʤɤ˽񤤤ƤΤǡ⼫ʬˤ碌ľƤ. Ūˤ
 <Directory "/usr/local/www/apache22/data">
 <Directory "/usr/local/web_dir/top">
ľȤˤʤ.
ScriptAlias
cgi ֤. ǥեȤΤޤޤǤϤʤʤΤǡŬ˿ǥ쥯ȥ(㤨 /usr/local/web_dir/cgi ʤ)äƤ顤ѹ褦. ξϡ
 ScriptAlias /cgi-bin/ "/usr/local/www/apache22/cgi-bin/"
Ƚ񤤤Ƥʬ㤨
 ScriptAlias /cgi-bin/ "/usr/local/web_dir/cgi/"
Ƚ뤳Ȥˤʤ(ǸΥå˺ʤ褦!!). ޤˤĤƤ
 <Directory "/usr/local/www/apache22/cgi-bin">
 <Directory "/usr/local/web_dir/cgi">
ȽʤȤȤʤΤդ褦.

Ǥϡ꤬ѹǤå褦.

ޤѰդ DocumentRoot ŬƤ index.html եѰդ褦.
apache ưǵưhttp://localhost ˥ơּʬѰդ index.htmlפȤ뤳Ȥǧ褦.

ˡcgi ΰ̣ϤŪͤ cgi ΥƥȤԤ. ޤ(ǸιԤԤƤʤȲϤʤΤϤ狼?)*8Υե f-test Ȥ̾Τ(ʬꤷ) cgi ǥ쥯ȥ֤.

 #!/bin/csh -f
 echo "Content-type: text/plain; charset=iso-8859-1"
 echo ""
 echo ""
 /usr/games/fortune  
 

ˤΥեμ¹ԥѡߥåꤷ褦.

 cd (ʬꤷ cgi ǥ쥯ȥ)
 chmod aog+x ./f-test

ԤäƤ顤 http://localhost/cgi-bin/f-test ˥Ƥߤ. Τä fortune η̤ web browser ˽ϤΤ.
ޤäƤǰΰ٤˼¹ԥѡߥåȤƤ.

 cd (ʬꤷ cgi ǥ쥯ȥ)
 chmod aog-x ./f-test

ơޤǤޤä¤ OK ʤΤ apahce Ƥߤ褦.

½

ޤǤκȤԤ.

SSL

¤ϡץȥ http ˽ä̿ƤȤǡϡ֤ΤޤޡץͥåȥήƤ.
Ĥޤꡤͥåȥ˵ޥʤɤ鸫ήƤǡϴݸǤꡤ̩ˤפʥǡʤɤ http ήȤϤȤƤǤʤ.

ͥåȥ̿Ź̿ˤǤˡˤĤ.
ΰĤǤ SSL Ȥäơweb Ѥ̿ץȥ http Ź沽ƤȤ褦ˤ褦*9.

ΤνȤơޤ̩Ⱦ*10(̤δطǡ3ܤޤ֤Ƥ뤬1ʬϤʤΤդ).

cd /usr/local/etc/apache22

openssl genrsa -out apache.key 1024

openssl req -new -x509 -days 1825 -key apache.key -out apache.crt 䤵뤬Ŭ(ȤŬǤ褤)˱.

ʤߤ˺ǸξϤȤꤢ 5ǯͭˤƤ. ܤ man req ȤĴ٤.

ˡե /usr/local/etc/apache22/extra/httpd-ssl.conf <VirtualHost _default_:443> ʬˤ

DocumentRoot
äͳʤо DocumentRoot ƱˤƤȤ褤.
ServerName
֤ݤΡ̾ˤʤ. ϥƥȤʤΤǥޥ̾Ǥ褤. 㤨 q3000.sci.osaka-u.ac.jp ȤޥʤС
 ServerName q3000.sci.osaka-u.ac.jp:443
Ƚ񤯤Ȥˤʤ. ʤߤˡꤹʤ httpd.conf ServeName ȤܤƱͤ
 ServerName q3000.sci.osaka-u.ac.jp:80
ꤷƤ̷⤬ʤƤ褤.
ServerAdmin
ʬΥ᡼륢ɥ쥹ѹƤ.
SSLCertificateFile
Ǻäե "/usr/local/etc/apache22/apache.crt" ľƤ.
SSLCertificateKeyFile
Ϥäե "/usr/local/etc/apache22/apache.key" ľƤ.

Τ褦ꤹ.

ˡ/usr/local/etc/apache22/httpd.con

 # Include etc/apache22/extra/httpd-ssl.conf

Ƚ񤤤ƤԤιƬ # äƤιԤͭˤ褦.

Ͻλ. apache 򤤤äƤ鵯ưľơ https://localhost ˥ơΤ https ³Ǥ뤳ȤΤ褦*11.

Basic ǧ

Apache ˤϼ¤¿εǽ.
ΰĤǤ Basic ǧڤϡǥ쥯ȥե˥ݤ˥桼̾ȥѥɤϤ׵ᤵ졤ʤȥǤʤȤȥ뵡ǽκǤñʤΤǤꡤñʤʤΤǡȤ褦ˤʤäƤȤ褤.
ǤƤߤ褦.

ޤоݤȤʤǥ쥯ȥѰդ.
(ʬꤷDocumentRoot)β test Ȥǥ쥯ȥꡤ basic ǧڤƤߤ褦.

ޤϥȤȥѥɤޤѥɥե.
ѥɥեϡ DocumentRoot ʲˤϺʤפ褦ˤʤȲȤޤ.
㤨 /usr/local/etc/apache22/Includes ˺Ȥȡ

cd /usr/local/etc/apache22/Includes

htpasswd -c ./passwdfile test-user "-c" ץĤȥȾǼե򿷵. ˥ե뤬Ϥޤä˾񤭤ƤޤΤǡ"-c" ĤȤϵĤ褦.

(桼 "test-user" ΥѥɤʹΤǿͤϤ)

ȤФ褤.

ʤߤˡbasic ǧڤͭˤ뤿ˡȤƤϥƥ¦ꤹˡ(httpd.conf ʤɤǤ)ȡƥǥ쥯ȥ .htaccess եꤹˡ뤬桼ʬǤԤȤ(ʬꥹΤǡѤκݤϤäĴ٤Ƥ)ΤǸԤǤäƤߤ褦.

ΤνȤơޤ httpd.conf <Directory "(ʬꤷDocumentRoot)"> ʲˤ

 AllowOverride None

ȤԤ

 AllowOverride AuthConfig

ˤƤ("AllowOverride ..." ȤԤʣΤǡսְ㤨ʤ褦).

ˡѰդ test Ȥǥ쥯ȥʲ˼Ƥ .htaccess Ȥե.

 AuthType Basic
 AuthName "basic auth test!"
 AuthUserFile  /usr/local/etc/apache22/Includes/passwdfile
 AuthGroupFile /dev/null
 require user test-user

줫顤Υǥ쥯ȥˤޤŬ index.html ѰդƤ.

apache ƤƤ apache ưнϴλ.
http://localhost/test (Ѱդǥ쥯ȥ) ˥Ƥߤơ桼̾ȥѥɤʹϤʤΤǡtest-user Ȥ桼̾졤ʬǾꤷѥɤƤߤ褦.
̵Ǥ OK .

ݡ

SSL ǧڤˤĤĴ٤(ä "쥪" ˤĤ. ĿŪˤϹڹ "ڹ" 20071125ε 褯狼äƤ褤Ȼפ).
ޤweb ФˤޤĤ륻ƥ(ȼ)ˤĤƤĴ٤.
ä "Allowoverride AuthConfig" ǤϤʤ "Allowoverride All" Ȥɤ줯餤Τ褯Ĵ٤.
ޤԤäȤˤĤ𤻤.


*1 http://www.apache.jp/misc/history.html ܸǤ줿 Apache β⤬
*2 http://www.apache.org
*3 ʬΥޥ˻˥󥹥ȡ뤷ƤߤʤФʤʤȤ¿ˤƤ⡤
*4 ֤ pkg_deinstall Ȥ
*5 μȤפФ. portsnap ȤΤ褤
*6 ޤǤʤֽפʡץեԽȤϸŪˤǤ褤ΤǸΥեΥХååפȤäƤ. Ūˤϡcp httpd.conf httpd.conf.ORG ʤɤǽʬǤ.
*7 󤽤Υǥ쥯ȥ꤬¸ߤʤȤʤΤǡ̵ mkdir ΥޥɤȤäƺäƤ
*8 Content-type θ˶ԤϤʤȤʤʤʤΤǤ̤˽񤯤٤.
*9 ¤ǧڤˤĤƤȤʤỌ̇̄Ϥʤ. ݡȤٶƤ餪
*10 ¯˸"쥪" Ǥ뤦ѥɤݸ⤷Ƥʤ. SSL 򤭤ȱѤСܼŪˤǧڶɤ򤭤Ѥ뤷ʤ. ޤ finger print ϤʤɤΡְʷϩǡꤷƳǧʤɤǤΤϤǤȻפɡ
*11 firefox ʤɤȡhttps ³ƤȤϥץβ¦˸Υޡɽ줿ꤹΤdzǧ䤹