世界中でもっとも使われているフリーのウェブサーバーソフト
Vine Linuxのインストール時に「インターネットサーバー」選択した場合、Vine Linux 3.2ではapacheが、Vine Linux 4.xはapache2が組み込まれます。クライアントパソコンのブラウザなどでhttp://xxx.xxx.xxx.xxx/にアクセスし、テストページが表示されることを確認します。
xxx.xxx.xxx.xxxはサーバーのIPアドレスです。次のコマンドでIPアドレスを調べることができます。
# /sbin/ifconfig ← 実行結果のinetアドレス欄に表示されます。
LAN内のクライアントからドメイン名でアクセスする場合は別途DNSサーバーを立てるか、hostsファイルにIPアドレス追記します。
設定ファイル/etc/httpd/conf/httpd.confの確認と編集を行います。
# vi /etc/httpd/conf/httpd.conf
ServerRoot /etc/httpd ← http://xxx.xxx.xxx.xxx/でアクセスされた時に表示されるhtmlを入れておくディレクトリ。
Options Include ExecCGI FollowSymLinks MultiViews ← SSI, CGIが有効
AllowOverride All ← .htaccessファイルが有効
UserDir public_html ← ユーザ毎のウェブディレクトリの設定
ServerName www.aaa_bbb.com ← サーバー名の設定 (これが無いとSquirrelmailのMessage-ID:がローカルIPアドレスになってしまいます。)
※他にも色々なパラメータがあります。apacheのウエブサイトにマニュアルがあるので、よく読んで設定しましょう。
※誤った設定はセキュリティホールになる恐れがあります。
設定ファイルを変更した場合、設定ファイルの再読み込みかサービスを再起動する必要があります。
# /etc/rc.d/init.d/httpd reload ← 再読み込み (apacheの場合)
# /etc/rc.d/init.d/apache2 reload ← 再読み込み (apache2の場合)
# /etc/rc.d/init.d/httpd restart ← 再起動 (apacheの場合)
# /etc/rc.d/init.d/apache2 restart ← 再起動 (apache2の場合)
mod_sslを使ってWebサーバの通信を暗号化します。
# cd /usr/share/ssl/certs
# make server.key ← サーバー用秘密鍵の作成を行います。
# openssl rsa -in server.key -out server.key ← サーバー起動時にパスワードを要求されないようにするため、秘密鍵からパスワードを抜きます。
# make server.csr ← サーバー用公開鍵を作成します。
(各パラメータは次のようにします)
Country Name (2 letter code)[AU]:JP ← 国名を入力する。
State or Province Name (full name) [Some-State]:Kanagawa ← 都道府県名を入力する。
Locality Name (eg, city) []:Yokohama ← 市区町村名を入力する。
Organization Name (eg, company) [Internet Widgits Pty Led]:www.aaa.com ← サーバーの名前を入力する。
Organization Unit Name (eg, section) []: ← Enter
Common Name (eg, YOUR name) []:www.aaa.com ← サーバーの名前を入力する。
Email Address []:webmaster@aaa.com ← 管理者のメールアドレスを入力する。
A challenge password []: ← Enter
An optional company name []: ← Enter
# openssl x509 -in server.csr -out server.pem -req -signkey server.key -days 365 ← 証明書を作成します
# chmod 400 server.* ← パーミッションを変更します。
# mv server.* /etc/httpd/conf ← 鍵と証明書を設置します。
apacheの設定ファイル/etc/httpd/conf/httpd.confを編集します。
# vi /etc/httpd/conf/httpd.conf
#SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt ← 行頭に#をつける
SSLCertificateFile /etc/httpd/conf/server.pem ← 追加する
#SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key ← 行頭に#をつける。
SSLCertificateKeyFile /etc/httpd/conf/server.key ← 追加する。
サービスを再起動します。
# /etc/rc.d/init.d/httpd restart
ブラウザから https://www.aaa.com/にアクセスし、セキュリティの警告ダイアログが出ればOKです。
※WAN側からアクセスできるようにするには、ポート443番をあける必要があります。
mod_rewriteを使ってwww.aaa.com/hoge.cgi?xxx=123などのクエリーストリングを使った動的URLをwww.aaa.com/123/などの静的URLにリアルタイムで書き換えます。
# vi .htaccess
RewriteEngine On ← 書き換えエンジンの有効化
RewriteCond %{REQUEST_FILENAME} !-f ← 実ファイルが存在する場合は書き換えない。
RewriteCond %{REQUEST_FILENAME} !-d ← 実ディレクトリがある場合は書き換えない。
RewriteRule ^(.*)$ hoge.cgi?xxx=$1 [L,QSA] ← 書き換えルール
ページ移転などの際、www.aaa.com/~xxx/へリダイレクトさせる場合は次のようにします
% vi .htaccess
Redirect permanent /~zzz/ http://www.aaa.com/~xxx/
有名なアクセスカウンタwwwcountを設置します。
% tar xvfz wwwcount2.5.tar.gz
% make config.h
% make cfg
% make all
# make install
# chmod 755 /home/httpd/html/cgi-bin/Count.cgi
# chmod 666 /usr/local/etc/Counter/data/sample.dat
% vi hoge.html
<img src="/home/httpd/html/cgi-bin/Count.cgi?df=sample.dat>" ← カウンタを埋め込みます。
バーチャルホストを使って、ひとつのIPアドレスでいくつかの名前ベースのウェブサイトを作ってみます。
# vi /etc/httpd/conf.d/virtualhost.conf
<VirtualHost *:80>
ServerName www.hogehoge.com ← 元あるサイト
DocumentRoot /home/httpd/html
</VirtualHost>
<VirtualHost *:80>
ServerName test.hogehoge.com ← バーチャルホスト名
DocumentRoot /home/test/public_html/ ← バーチャルホストのドキュメントルート
DirectoryIndex index.html
ErrorLog logs/test-error_log ← エラーログの指定
CustomLog logs/test-access_log combined env=!no_log ← カスタムログの設定
</VirtualHost>