トップ > Fedora Core4によるサーバーの構築 >

Apache(Webサーバー)の構築

Apacheのインストールと設定

  1. rootでログインする。
  2. 以下のコマンドを実行して,Apacheをインストールする。
    # yum install httpd
  3. 日本語ページの文字化けが起こらないように,/etc/httpd/conf/httpd.confの以下の行を修正する。
    AddDefaultCharset off
  4. 以下のコマンドを実行して,Apacheを起動する。
    # /etc/init.d/httpd start
  5. 以下のコマンドを実行して,Apacheの標準のラン・レベルをonにする。
    # chkconfig httpd on
  6. Anonymizerなどを利用して,外部からこのWebサーバーにアクセスできるか確認する。

DAVアクセス可能なディレクトリの設定

 認証されたLDAPグループmanagerが,WebDAVにより/var/www/html/abcディレクトリに書き込めるようにします。

  1. rootでログインする。
  2. /var/www/html/abcディレクトリを作成する。
  3. 以下のコマンドを実行して,/var/www/html/abcディレクトリのアクセス権限を変更する。
    # chmod 775 /var/www/html/abc
    # chown apache:manager /var/www/html/abc
    • ディレクトリのユーザには,「apache」を設定。
  4. /etc/httpd/conf/httpd.confに以下の行を追加する。
    
    <IfModule mod_dav_fs.c>
        # Location of the WebDAV lock database.
        DAVLockDB /var/lib/dav/lockdb
    </IfModule>
    
    
    LDAPTrustedCA /etc/openldap/cacerts/cacert.pem
    LDAPTrustedCAType BASE64_FILE
    <Directory "/var/www/html/abc">
        DAV On
        #SSLRequireSSL
        AuthType Basic
        AuthName WebDAV
        AuthLDAPGroupAttributeIsDN off
        AuthLDAPGroupAttribute memberUid
        AuthLDAPURL ldaps://192.168.0.1/ou=People,dc=shitomi,dc=jp?uid?
        <LimitExcept GET HEAD OPTIONS>
            #Require user abc
            Require group cn=manager,ou=Groups,dc=shitomi,dc=jp
            Order deny,allow
            Deny from all
            Allow from 192.168.0.0/24
        </LimitExcept>
    </Directory>
    
    • LDAPTrustedCAは,CAの証明書を指定。
    • LDAPTrustedCATypeは,証明書ファイルのフォーマット形式を指定。
    • SSLRequireSSLは,SSLを利用(今回は使用しない)。
    • AuthType Basicは,Basic認証。
    • AuthName WebDAVは,ダイアログに表示される文章を指定。
    • AuthLDAPURLは,認証に用いるLDAPサーバーのURLと検索パラメータを指定。
    • Require user abcは,認証するユーザをabcに指定(今回は指定しない)。登録している全てのユーザを指定する場合は,Require valid-user。
    • Require groupは,認証するグループを指定。
    • Allow from 192.168.0.0/24は,192.168.0.*からの要求を許可。
  5. 以下のコマンドを実行して,Apacheを再起動する。
    # /etc/init.d/httpd restart
    • 以下のコマンドを実行することにより,設定ファイルが正しいかどうかを確認することが出来る。
      # /etc/rc.d/init.d/httpd configtest ←/etc/httpd/conf/httpd.confの文法チェック
      Syntax OK ←このように表示されたら大丈夫

Windows2000によるWebDAV接続

  1. [マイ ネットワーク]から[ネットワーク プレースの追加]を選択して,"ネットワーク プレースの場所を入力してください:"に「http://192.168.0.1」を入力する。
    Windows2000によるWebDAV接続方法(その1)/Apache/Fedora Core
  2. 次の画面においては,ユーザ名とパスワードを入力する。
    Windows2000によるWebDAV接続方法(その2)/Apache/Fedora Core
  3. "このネットワーク プレースの名前を入力してください:"に,このフォルダの名前を適当に入力する。
    Windows2000によるWebDAV接続方法(その3)/Apache/Fedora Core

Mac OS X 10.3によるWebDAV接続

  1. Finderのメニューから[移動] - [サーバへ接続]を選択する。
  2. 現れたダイアログボックスのアドレスの部分に,「http://192.168.0.1」を入力する。
    Mac OS XによるWebDAV接続方法(その1)/Apache/Fedora Core
  3. ユーザ名とパスワードを入力する。
    Mac OS XによるWebDAV接続方法(その2)/Apache/Fedora Core
  4. デスクトップにWebDAVフォルダがマウントされる。

DreamweaverによるWebDAV接続

  1. Dreamweaverにおいて,新規にサイトを作成する。
    DreamweaverによるWebDAV接続(その1)/Apache/Fedora Core
  2. このサイトの[リモート情報]の[アクセス]に「WebDAV」を選択する。
    DreamweaverによるWebDAV接続(その2)/Apache/Fedora Core
  3. WebDAVの設定において,[URL:]に「http://192.168.0.1/abc」,[ユーザー名]に「abc」,[パスワード]にabcのパスワードを,それぞれ入力する。
    DreamweaverによるWebDAV接続(その3)/Apache/Fedora Core

バーチャルホストの作成

 ns.shitomi.jp及びmail.shitomi.jpのDocumentRootに/var/www/html/error,www.shitomi.jp,www.shitomi.net及びwww.shitomi.comのDocumentRootに/var/www/html/wwwをそれぞれ指定します。

  1. rootでログインする。
  2. /var/www/html/errorディレクトリ及び/var/www/html/wwwディレクトリを作成する。
  3. 以下のコマンドを実行して,アカウントabc(Administratorsグループに所属)が/var/www/html/wwwディレクトリに書き込めるように,アクセス権限を変更する。
    # chmod 775 /var/www/html/www
    # chown apache:Administrators /var/www/html/www
  4. SFTPにより,アカウントabcで/var/www/html/wwwディレクトリへのアップロードを行うことができることを確認する。
  5. /etc/httpd/conf/httpd.confの最終行に,以下のような行を追加する。
    
    NameVirtualHost 61.205.232.19:80
    
    <VirtualHost 61.205.232.19:80>
        ServerAdmin postmaster@shitomi.jp
        DocumentRoot /var/www/html/error
        ServerName ns.shitomi.jp
    </VirtualHost>
    
    <VirtualHost 61.205.232.19:80>
        ServerAdmin postmaster@shitomi.jp
        DocumentRoot /var/www/html/error
        ServerName mail.shitomi.jp
    </VirtualHost>
    
    <VirtualHost 61.205.232.19:80>
        ServerAdmin postmaster@shitomi.jp
        DocumentRoot /var/www/html/www
        ServerName www.shitomi.jp
    </VirtualHost>
    
    <VirtualHost 61.205.232.19:80>
        ServerAdmin postmaster@shitomi.net
        DocumentRoot /var/www/html/www
        ServerName www.shitomi.net
    </VirtualHost>
    
    <VirtualHost 61.205.232.19:80>
        ServerAdmin postmaster@shitomi.com
        DocumentRoot /var/www/html/www
        ServerName www.shitomi.com
    </VirtualHost>
    
  6. 以下のコマンドを実行して,Apacheを再起動する。
    # /etc/init.d/httpd restart

ユーザーごとのWeb制作

 アカウントabcにおいて,Webページを/home/abc/public_htmlで作成可能にするとともに,CGIを/home/abc/public_html/cgi-binで実行可能にする。

  1. アカウントabcでログインする。
  2. 以下のコマンドを実行して,Webページ用のディレクトリを作成する。
    $ mkdir -p /home/abc/public_html/cgi-bin
  3. rootでログインする。
  4. 以下のコマンドを実行して,アカウントabcのパーミッションを変更する。
    # chmod 755 /home/abc
  5. 以下のコマンドを実行して,セキュリティコンテキストを変更する。
    # chcon -R system_u:object_r:httpd_user_content_t /home/*/public_html
  6. /etc/httpd/conf/httpd.confの以下の行を修正(赤字)して,ユーザーのWebページ作成を可能にする。
    
    <IfModule mod_userdir.c>
        #
        # UserDir is disabled by default since it can confirm the presence
        # of a username on the system (depending on home directory
        # permissions).
        #
        #UserDir disable
    
        #
        # To enable requests to /~user/ to serve the user's public_html
        # directory, remove the "UserDir disable" line above, and uncomment
        # the following line instead:
        #
        UserDir public_html
    
    </IfModule>
    
    #
    # Control access to UserDir directories.  The following is an example
    # for a site where these directories are restricted to read-only.
    #
    <Directory /home/*/public_html>
        AllowOverride FileInfo AuthConfig Limit
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
        <Limit GET POST OPTIONS>
            Order allow,deny
            Allow from all
        </Limit>
        <LimitExcept GET POST OPTIONS>
            Order deny,allow
            Deny from all
        </LimitExcept>
    </Directory>
    
    
  7. /etc/httpd/conf/httpd.confの以下の行に,ユーザーabcがCGIを実行可能にするための行(赤字)を追加する。
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    ScriptAlias /~abc/cgi-bin/ "/home/abc/public_html/cgi-bin/"

    
    <Directory "/var/www/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>
    <Directory "/home/*/public_html/cgi-bin">
        Options +ExecCGI
        SetHandler cgi-script
    </Directory>
    
  8. /etc/httpd/conf/httpd.confの以下の行のコメントアウトをはずす。
    #AddHandler cgi-script .cgi
  9. 以下のコマンドを実行して,suEXECのパーミッションを変更する。
    # chmod 4511 /usr/sbin/suexec
  10. 以下のようなドメインhttpd_tに関するアクセス権限の設定内容を,/etc/selinux/targeted/src/policy/domains/program/mypolicy.teに追加する。
    can_exec(httpd_t, httpd_user_content_t)
    r_dir_file(httpd_t, httpd_user_content_t)
  11. 以下のコマンドを実行して,設定をシステムに反映させる。
    # cd /etc/selinux/targeted/src/policy
    # make clean
    # make reload
  12. 以下のコマンドを実行して,Apacheを再起動する。
    # /etc/init.d/httpd restart

SSLの利用のためのApacheの設定

 443番ポート(SSL)でApacheが利用できるようにします。

  1. rootでログインする。
  2. 以下のコマンドを実行して,mod_sslをインストールする。
    # yum install mod_ssl
  3. /var/www/html/dbディレクトリを作成する。
  4. /etc/httpd/conf.d/ssl.confの以下の行(赤字)を追加する。
    <VirtualHost _default_:443>

    # General setup for the virtual host, inherited from global configuration
    #DocumentRoot "/var/www/html"
    #ServerName www.example.com:443
    DocumentRoot "/var/www/html/db"
    ServerName db.shitomi.jp:443
  5. 以下のコマンドを実行して,Apacheを再起動する。
    # /etc/init.d/httpd restart
  6. https://db.shitomi.jpにアクセスすることにより,Apacheの動作を確認する。

サイト証明書署名要求と秘密鍵の作成

  1. rootでログインする。
  2. 以下のコマンドを実行して,Webサーバーのサイト証明書署名要求(csr.pem)と秘密鍵(privkey.pem)を作成する。
    # cd /tmp
    # openssl req -new -out csr.pem
  3. 続いて,以下のように入力する。
    Using configuration from /usr/share/ssl/openssl.cnf
    Generating a 1024 bit RSA private key
    .......................++++++
    ............++++++
    writing new private key to 'privkey.pem'
    Enter PEM pass phrase:[パスワードを入力]
    Verifying password - Enter PEM pass phrase:[パスワードを再入力]
    -----
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [GB]:JP
    State or Province Name (full name) [Berkshire]:Miyagi
    Locality Name (eg, city) [Newbury]:Sendai
    Organization Name (eg, company) [My Company Ltd]:Individual
    Organizational Unit Name (eg, section) []:[リターンキーを押す]
    Common Name (eg, your name or your server's hostname) []:db.shitomi.jp
    Email Address []:[リターンキーを押す]

    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:[リターンキーを押す]
    An optional company name []:[リターンキーを押す]
  4. 以下のコマンドを実行することにより,秘密鍵(privkey.pem)からパスフレーズを削除した秘密鍵(localhost.key)を作成する。
    # openssl rsa -in /tmp/privkey.pem -out /etc/pki/tls/private/localhost.key

構築した認証局(CA)によるサーバー証明書の作成

  1. rootでログインする。
  2. 以下のコマンドを実行して,構築したCAのルート証明書(ca.cer)を作成する。
    # openssl x509 -inform pem -outform der -in /etc/pki/CA/cacert.pem -out /tmp/ca.cer
  3. このルート証明書(ca.cer)をクライアントにインポートする。
  4. 以下のコマンドを実行して,Webサーバーのサイト証明書署名要求(csr.pem)から,サーバー証明書(localhost.crt)を作成する。
    # cd /etc/pki/tls/misc
    # openssl ca -out /etc/pki/tls/certs/localhost.crt -infiles /tmp/csr.pem
  5. 以下のコマンドを実行して,Apacheを再起動する。
    # /etc/init.d/httpd restart
  6. https://db.shitomi.jpにアクセスすることにより,構築したCA及びWebサーバー(db.shitomi.jp)が,そのクライアントから認証されることを確認する。

(参考)商業認証局からのサーバー証明書の取得

  1. /tmp/csr.pemを,日本ベリサインなどの商業認証局に提出して,Apacheのサーバー証明書を発行してもらい,これをserver.crtというファイル名にして,LinuxPCの/etc/httpd/conf/ssl.crtディレクトリにコピーする。
  2. rootでログインする。
  3. 以下のコマンドを実行して,Apacheを再起動する。
    # /etc/init.d/httpd restart
  4. https://db.shitomi.jpにアクセスすることにより,Apacheの動作を確認する。

 このサイトに書かれていることが原因でトラブルが発生しても,私は責任を取ることができません。したがいまして,ここで述べられていることに関する実行は,自己責任でお願いいたします。なお,このサイトはリンクフリーで,リンク時の連絡も不要です。

サイト内関連リンク:OpenLDAP