目的
Webシステム構築を目的として、まずは超基礎的なWebサーバの構築と動作を確認する。
環境条件
- Webサーバ
- EC2:t2.micro
- OS:Red Hat Enterprise Linux 8 (HVM), SSD Volume Type
- Disk:汎用SSD(GP2) 10GB
セキュリティグループの設定等はいい感じに。
構築手順
ec2-userでログイン
rootユーザにスイッチ
$ sudo su -
httpパッケージの存在確認
# yum info httpd
httpパッケージのインストール
# yum install -y httpd
Complete!の出力を確認する。
httpdサービスの停止を確認
# service httpd status
Active: inactive (dead)の出力を確認する。
httpdサービスを起動する
# service httpd start
Redirecting to /bin/systemctl start httpd.service
再度httpdサービスのステータスを確認する
# service httpd status
Active: active (running)の出力を確認する。
ブラウザからWebサーバの「パブリックDNS:80」に接続し、
Red Hat Enterprise Linux Test Pageが表示されることを確認する。
Webサーバの基本動作
以下2点ほど確認しておく。
- DocumentRootとコンテンツの配置
- 別ポートでのWebサーバ起動
1. DocumentRootとコンテンツの配置
DocumentRoot
DocumentRootとはざっくりいうと、自分で作ったコンテンツを
Apache HTTP ServerでWebサービスとして提供するための置き場所。
デフォルトは、以下となっている。
/var/www/html
DocumentRootの変更や設定の確認については、
以下ファイルによって可能。
/etc/httpd/conf/httpd.conf
(:set numberを実行の上、一部抜粋)
117 #
118 # DocumentRoot: The directory out of which you will serve your
119 # documents. By default, all requests are taken from this directory, but
120 # symbolic links and aliases may be used to point to other locations.
121 #
122 DocumentRoot "/var/www/html" #←ここを変更することでDocumentRootが変更可能
コンテンツの配置
まずは、DocumentRootにindex.htmlファイルを配置してみる。
(中身はなんでもいい。)
index.html
この状態で、ブラウザからWebサーバの「パブリックDNS:80」に接続すると、
Red Hat Enterprise Linux Test Pageが表示されなくなり、
index.htmlの中に記載した内容が表示される。
DocumentRootにindex.が存在しない場合、
Testページを表示するが、存在する場合、index.を表示する。
次に、DocumentRootにtest.htmlファイルを配置してみる。
(中身はなんでもいい。)
test.html
この状態で、ブラウザからWebサーバの「パブリックDNS:80/test.html」に接続すると、
test.htmlを表示することができる。
2. 別ポートでのWebサーバ起動
80番ポート以外でのWebサーバの起動が必要な場合に、DocumentRootと同じく、
以下ファイルを変更することで対応することが可能。
(:set numberを実行の上、一部抜粋)
37 # Listen: Allows you to bind Apache to specific IP addresses and/or
38 # ports, instead of the default. See also the <VirtualHost>
39 # directive.
40 #
41 # Change this to Listen on specific IP addresses as shown below to
42 # prevent Apache from glomming onto all bound IP addresses.
43 #
44 #Listen 12.34.56.78:80
45 Listen 80
45行目のListen 80を Listen 10000等に変更し、プロセスを再起動することで、
10000ポートでのWebサーバの起動が可能になる。
次回は、
Webシステム構築(超基礎)②:APサーバ構築と基本動作
です。