2013年7月28日日曜日

カゴヤVPSのcent os6サーバにてWeb サーバーの設定手順

  1. rootアカウントでログインします。
    [root@v0000 ~]#

    プロンプト表示に続けて次のコマンドを入力します。
    [root@v0000 ~]# vi /etc/httpd/conf/httpd.conf
    • 「vi」と「/etc/httpd/conf/httpd.conf」の間はスペースが入ります。

    入力したらキーボードの Enterキーを押します。

  2. viエディタで[httpd.conf]の内容が表示されます。

    #
    # This is the main Apache server configuration file. It contains the
    # configuration directives that give the server its instructions.
    # See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.
    # In particular, see
    # <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
    # for a discussion of each configuration directive.
    #
    #
    # Do NOT simply read the instructions in here without understanding
    # what they do. They're here only as hints or reminders. If you are unsure
    # consult the online docs. You have been warned.
    #
    # The configuration directives are grouped into three basic sections:
    #  1. Directives that control the operation of the Apache server process as a
    #     whole (the 'global environment').
    #  2. Directives that define the parameters of the 'main' or 'default' server,
    #     which responds to requests that aren't handled by a virtual host.
    #     These directives also provide default values for the settings
    #     of all virtual hosts.
    #  3. Settings for virtual hosts, which allow Web requests to be sent to
    #     different IP addresses or hostnames and have them handled by the
    #     same Apache server process.

    httpd.conf を編集することで、Apache の各種設定を行います。

  3. 例えば、「ServerAdmin root@localhost」という記述を探します。
    # ServerAdmin: Your address, where problems with the server should be
    # e-mailed. This address appears on some server-generated pages, such
    # as error documents. e.g. admin@your-domain.com
    #
    ServerAdmin root@localhost

    ServerAdmin ディレクティブでは、サーバー管理者のメールアドレスを設定します。
    ServerAdmin ディレクティブで設定したメールアドレスは、Webサイトでエラーメッセージが表示されるときなどに、問い合わせ先メールアドレスとして表示することができますが、メールアドレスを表示することで大量の迷惑メールが届くことが懸念されます。
    このため、ServerSignature ディレクティブをデフォルトの On から EMail に変更しなければ表示されることはありません。
    ■参考URL: Apache HTTP サーバ ドキュメント - ServerAdmin ディレクティブ
        http://httpd.apache.org/docs/2.2/ja/mod/core.html#serveradmin

    キーボードの「i」キーを押し、viエディタを入力モードにすると内容を編集できます。
    サーバー管理者のメールアドレスが、「webmaster@example.com」の場合、
    ServerAdmin root@localhost」という記述を下記の通り編集します。
    # ServerAdmin: Your address, where problems with the server should be
    # e-mailed. This address appears on some server-generated pages, such
    # as error documents. e.g. admin@your-domain.com
    #
    ServerAdmin webmaster@example.com

    • root@localhost の部分を連絡先メールアドレスに書き換えます。


  4. #ServerName www.example.com:80」という記述を探します。
    # ServerName gives the name and port that the server uses to identify itself.
    # This can often be determined automatically, but we recommend you specify
    # it explicitly to prevent problems during startup.
    #
    # If this is not set to valid DNS name for your host, server-generated
    # redirections will not work. See also the UseCanonicalName directive.
    #
    # If your host doesn't have a registered DNS name, enter its IP address here.
    # You will have to access it by its address anyway, and this will make
    # redirections work in a sensible way.
    #
    #ServerName www.example.com:80

    ServerName ディレクティブでは、Web サーバーのホスト名を設定します。
    ServerName ディレクティブで設定したホスト名は、エラーメッセージなどで表示されたり、リダイレクトするときの URL にも利用されます。
    ■参考URL: Apache HTTP サーバ ドキュメント - ServerName ディレクティブ
        http://httpd.apache.org/docs/2.2/ja/mod/core.html#servername

    サーバーのホスト名を設定するには、「#ServerName www.example.com:80」という記述を下記の通り編集します。
    # ServerName gives the name and port that the server uses to identify itself.
    # This can often be determined automatically, but we recommend you specify
    # it explicitly to prevent problems during startup.
    #
    # If this is not set to valid DNS name for your host, server-generated
    # redirections will not work. See also the UseCanonicalName directive.
    #
    # If your host doesn't have a registered DNS name, enter its IP address here.
    # You will have to access it by its address anyway, and this will make
    # redirections work in a sensible way.
    #
    ServerName www.example.com:80

    • 行頭の「#」を削除します。
    • www.example.com の部分を Webサイトの URL に使用するホスト名に書き換えます。

    ここで設定するホスト名は、DNSサーバーに問い合わせることでホスト名からIPアドレスが名前解決できる必要があります。


  5. DocumentRoot "/var/www/html"」という記述を探します。
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    #
    DocumentRoot "/var/www/html"

    DocumentRoot ディレクティブでは、Webサイトのコンテンツ(HTMLファイルなど)を格納するディレクトリ(ドキュメントルート)を設定します。
    このマニュアルでは、初期設定のまま変更しませんが、必要に応じてご変更ください。
    <Directory "/var/www/html">」という記述を探します。
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "/var/www/html">

    DocumentRoot ディレクティブでドキュメントルートを変更した場合は、ドキュメントルートに合わせて書き換えます。
    このマニュアルでは、初期設定のまま変更しませんが、必要に応じてご変更ください。
    DocumentRoot ディレクティブで設定したディレクトリに「index.html」を配置した場合、Webブラウザで ServerName ディレクティブで設定したホスト名(このマニュアルの例では、http://www.example.com/)にアクセスすると表示されます。
    ■参考URL: Apache HTTP サーバ ドキュメント - DocumentRoot ディレクティブ
        http://httpd.apache.org/docs/2.2/ja/mod/core.html#documentroot


  6. httpd.conf の編集が完了したら、キーボードの Escキーを押し、viエディタをコマンドモードに戻します。
    編集内容を保存するため、次のコマンドを入力します。
    :w

    入力したらキーボードの Enterキーを押します。

  7. viエディタを終了するため、次のコマンドを入力します。
    :q

    入力したらキーボードの Enterキーを押します。

  8. 設定ファイルの編集内容を反映させるため、httpdを再起動します。
    プロンプト表示に続けて次のコマンドを入力します。
    [root@v0000 ~]# vi /etc/httpd/conf/httpd.conf
    [root@v0000 ~]# /etc/rc.d/init.d/httpd restart
    • 「/etc/rc.d/init.d/httpd」と「restart」の間はスペースが入ります。

    入力したらキーボードの Enterキーを押します。

  9. httpdの再起動が完了すると、下記のように表示されます。
    [root@v0000 ~]# vi /etc/httpd/conf/httpd.conf
    [root@v0000 ~]# /etc/rc.d/init.d/httpd restart
    httpd を停止中:                                            [  OK  ]
    httpd を起動中:                                            [  OK  ]
    [root@v0000 ~]#

    「httpd を起動中: [OK]」と表示されれば、正しく再読み込みできています。

  10. Webブラウザで、設定したホスト名(このマニュアルの例では、http://www.example.com/)にアクセスします。

    Apache の初期画面が表示されます。

0 件のコメント:

コメントを投稿