« NCLP Practice Notes | 首頁 | 2006/10, Vol. 129 PChome Magazine »

2006年09月29日

Apache2 on SuSE 9.3 設定備忘

設置密碼驗證

設定連入 /home/someone/public_html (/~someone) 時啟用密碼驗證

su - someone

/usr/sbin/htpasswd2 -c .htpasswd admin

New password: password_for_admin
Re-Type new password: password_for_admin

vi public_html/.htaccess

AuthType Basic
AuthName "Password Required"
AuthUserFile "/home/someone/.htpasswd"
Require user admin
or
Require valid-user

設定 SSL 加密的 http 服務

製作 SSL 憑證

openssl req -new -x509 -newkey rsa:1024 -days 3650 -keyout server.key -out server.crt

Enter PEM pass phrase: your_phrase
Verifying - Enter PEM pass phrase: your_phrase

Country Name (2 letter code) [AU]: TW
State or Province Name (full name) [Some-State]: Taiwan
Locality Name (eg, city) []: Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]: My Labs
Organization Unit Name (eg, section) []: MIS
Common Name (eg, YOUR name) []: www.mydomain.com (same as web server name)
Email Address []: webmaster@mydomain.com

openssl req --help for listing options

openssl rsa -in server.key -out server.key

Enter pass phrase for server.key: your_phrase

mv server.key /etc/apache2/ssl.key/

mv server.crt /etc/apache2/ssl.crt/

Apache2 HTTP Server 環境設定

vi /etc/sysconfig/apache2

APACHE_SERVER_FLAGS="-D SSL"

cd /etc/apache2/vhosts.d

cp vhost-ssl.template vhost-ssl.conf

vi vhost-ssl.conf

#<IfDefine SSL>
#<IfDefine !NOSSL>

...

#</IfDefine>
#</IfDefine>

重新啟動 Apache2 httpd

/etc/init.d/apache2 restart

httpd2 -S

VirtualHost configuration:

_default_:443        www.mydomain.com (/etc/apache2/vhosts.d/vhost-ssl.conf:35)

Syntax OK

netstat -ntulp | grep httpd

tcp 80 LISTEN httpd2-prefor
tcp 443 LISTEN httpd2-prefor

同一 IP 設置多個虛擬站台

echo "NameVirtualHost *:80" >> /etc/apache2/default-server.conf

cd /etc/apache2/vhosts.d

cat vhost.template | tee www1.conf www2.conf > /dev/null

vi www1.conf

ServerName www1.mydomain.com
DocumentRoot /srv/www/vhosts/www1
ScriptAlias /cgi-bin/ "/srv/www/vhosts/www1/cgi-bin"
<Directory "/srv/www/vhosts/www1/cgi-bin">
...
<Directory "/srv/www/vhosts/www1">
...

vi www2.conf

same as above, but www1 → www2

vi www.conf (for default server)

<VirtualHost *:80>

ServerName www.mydomain.com

</VirtualHost>

mkdir -p /srv/www/vhosts/www1/cgi-bin /srv/www/vhosts/www2/cgi-bin

/etc/init.d/apache2 reload

httpd2 -S

*:80 is a NameVirtualHost
default server www.mydomain.com (/etc/apache2/vhosts.d/www.conf:1)
port 80 namevhost www.mydomain.com (/etc/apache2/vhosts.d/www.conf:1)
port 80 namevhost www1.mydomain.com (/etc/apache2/vhosts.d/www1.conf:13)
port 80 namevhost www2.mydomain.com (/etc/apache2/vhosts.d/www2.conf:13)


References:

Posted by Jamyy at 2006年09月29日 12:45

Trackback Pings

TrackBack URL for this entry:
http://cha.homeip.net/cgi-bin/mt/mt-tb.cgi/231