Webサーバー Apacheの設定と起動

Apacheの設定と起動
ここでは、Webサーバーとして最もインストール数が多いといわれている、Apache HTTP Server(以下、Apache)の設定を行います。Apacheの役割は、Linux上の、指定したディレクトリをクライアントに公開し、ディレクトリに置かれた情報を、クライアントから参照できるようにすることです。Apacheで公開されるディレクトリは、インターネットからのアクセスにも対応するため、セキュリティ対応も同時に行う必要があります。セキュリティ対策はパスワード認証やIPアドレスによるアクセス制限などがありますが、ここでは、iptableによるファイアウォールの設定を行います。
Apacheのインストールを確認する
yumコマンドでパッケージのインストール状況を確認する
[root@www ~]# yum list installed | grep httpd⏎ httpd.x86_64 2.2.15-39.el6.centos httpd-manual.noarch 2.2.15-39.el6.centos httpd-tools.x86_64 2.2.15-39.el6.centos [root@www ~]#
- 「yum」コマンドを入力
- 「list installed」でインストールしたパッケージを確認する
- インストールしたパッケージの中から、「httpd」という文字をgrepコマンドで検索する
Apache HTTP Server
WebブラウザでURLを指定すると、そのURLに対応したWebサーバーにアクセスし、WebブラウザにWebページを転送します。このWebサーバーとして、世界で最も使われているのが、Apache HTTP Server、通称Apacheです。Apacheは、Linuxだけでなく、MacOS、Windowsにも対応しています。
Apacheのバージョンを確認するには
コマンドラインで、「httpd -v」と入力します。バージョンに限らず、Apacheのコマンドラインオプションを確認するには、「httpd -h」と入力します。manコマンドを利用すると、より詳細な説明が表示されます。
httpdの設定を書き換える
Apacheの設定ファイルを開く
httpd.confは大きな設定ファイルなので、vi起動後に、「/」で修正個所を探します。続けて同じ文字を検索する場合は、「n」を入力します。デフォルトの設定は、行頭に#を付けて無効にします。
viでhttpd.confを開く
# vi /etc/httpd/conf/httpd.conf⏎
viが起動しました。
# 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 dpro@dekiru.gr.jp (※) #
※ServerAdminを書き換える。
# 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 www.dekiru.gr.jp:80 (※)
※ServerNameを書き換える。
#UseCanonicalName Off UseCanonicalName On (※)
※UseCanonicalNameの設定をOnにする。
# The index.html.var file (a type-map) is used to deliver content- # negotiated documents. The MultiViews Option can be used for the # same purpose, but it is much slower. # DirectoryIndex index.html index.html.var index.htm index.php (1) # # Specify a default charset for all content served; this enables # interpretation of all content as UTF-8 by default. To use the # default browser choice (ISO-8859-1), or to allow the META tags # in HTML content to override this choice, comment out this # directive: # AddDefaultCharset UTF-8 (2)
- index.htm index.phpを追加
- AddDefaultCharsetがUTF-8になっていることを確認する
保存して終了します。ServerNameには、第8回目〜10回目で設定したホスト名を指定してください。
Apacheの状態を確認する
Apacheの自動起動の設定を確認する
[root@www ~]# chkconfig --list httpd⏎ httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@www ~]#
1.「chkconfig」コマンドを入力2.「list」状態を表示3.「httpdz」Apacheのサービス名
Apacheがまだ起動されていないことを確認しました。
Apacheの起動と自動起動を設定する
Apacheを起動する
「service」コマンドを入力
[root@www ~]# service httpd start⏎ httpd を起動中: [ OK ]
Apacheを自動起動に設定する
「chkconfig」コマンドを入力
[root@www ~]# chkconfig httpd on⏎
Apacheの自動起動の設定変更を確認する
「chkconfig」コマンドを入力
[root@www ~]# chkconfig --list httpd⏎ httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@www ~]#
GUIでのサービスの確認と設定
[システム]メニュー[管理]−[サービス]から、GUIのサービス管理ツールが起動できます。サービスの開始・停止・カスタマイズ(ランレベルの有効・無効)が行えます。