Apacheの設定と起動
ここでは、Webサーバーとして最もインストール数が多いといわれている、Apache HTTP Server(以下、Apache)の設定を行います。Apacheの役割は、Linux上の、指定したディレクトリをクライアントに公開し、ディレクトリに置かれた情報を、クライアントから参照できるようにすることです。Apacheで公開されるディレクトリは、インターネットからのアクセスにも対応するため、セキュリティ対応も同時に行う必要があります。セキュリティ対策はパスワード認証やIPアドレスによるアクセス制限などがありますが、ここでは、iptableによるファイアウォールの設定を行います。
Apacheのインストールを確認する
yumコマンドでパッケージのインストール状況を確認する
1 | [root@www ~]# yum list installed | grep httpd⏎ |
2 | httpd.x86_64 2.2.15-39.el6.centos |
3 | httpd-manual.noarch 2.2.15-39.el6.centos |
4 | httpd-tools.x86_64 2.2.15-39.el6.centos |
- 「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を開く
1 | # vi /etc/httpd/conf/httpd.conf⏎ |
viが起動しました。
1 | # ServerAdmin: Your address, where problems with the server should be |
2 | # e-mailed. This address appears on some server-generated pages, such |
3 | # as error documents. e.g. admin@your-domain.com |
5 | #ServerAdmin root@localhost |
6 | ServerAdmin dpro@dekiru.gr.jp (※) |
※ServerAdminを書き換える。
1 | # If your host doesn't have a registered DNS name, enter its IP address here. |
2 | # You will have to access it by its address anyway, and this will make |
3 | # redirections work in a sensible way. |
5 | #ServerName www.example.com:80 |
6 | ServerName www.dekiru.gr.jp:80 (※) |
※ServerNameを書き換える。
※UseCanonicalNameの設定をOnにする。
01 | # The index.html.var file (a type-map) is used to deliver content- |
02 | # negotiated documents. The MultiViews Option can be used for the |
03 | # same purpose, but it is much slower. |
05 | DirectoryIndex index.html index.html.var index.htm index.php (1) |
08 | # Specify a default charset for all content served; this enables |
09 | # interpretation of all content as UTF-8 by default. To use the |
10 | # default browser choice (ISO-8859-1), or to allow the META tags |
11 | # in HTML content to override this choice, comment out this |
14 | AddDefaultCharset UTF-8 (2) |
- index.htm index.phpを追加
- AddDefaultCharsetがUTF-8になっていることを確認する
保存して終了します。ServerNameには、第8回目〜10回目で設定したホスト名を指定してください。
Apacheの状態を確認する
Apacheの自動起動の設定を確認する
1 | [root@www ~]# chkconfig --list httpd⏎ |
2 | httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off |
1.「chkconfig」コマンドを入力2.「list」状態を表示3.「httpdz」Apacheのサービス名
Apacheがまだ起動されていないことを確認しました。
Apacheの起動と自動起動を設定する
Apacheを起動する
「service」コマンドを入力
1 | [root@www ~]# service httpd start⏎ |
Apacheを自動起動に設定する
「chkconfig」コマンドを入力
1 | [root@www ~]# chkconfig httpd on⏎ |
Apacheの自動起動の設定変更を確認する
「chkconfig」コマンドを入力
1 | [root@www ~]# chkconfig --list httpd⏎ |
2 | httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
GUIでのサービスの確認と設定
[システム]メニュー[管理]−[サービス]から、GUIのサービス管理ツールが起動できます。サービスの開始・停止・カスタマイズ(ランレベルの有効・無効)が行えます。