提供:EELの自由帳
移動先: 案内検索

ヘルプ:Webサーバー構築(Apache)(AlmaLinux)

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(AlmaLinux)  > Webサーバー構築(Apache)(AlmaLinux)

概要

httpd をインストールしてWebサーバーを構築します。Webサーバー(Apache)はInternet Explorer等のブラウザからWebページをみれるようにするためのサーバーです。なお、HTTP は 80/TCP を使用します。

ここでは、ホームページスペース提供サービスを行っている一般的なWebサーバーと同様に以下のことができるようにする。

  • CGIは任意のディレクトリで実行できるようにする。
  • SSIは拡張子がshtmlのもののみ実行できるようにする。
  • .htaccessを使用できるようにする。
  • PHPを使用できるようにする。

Webサーバーインストール

httpdインストール

[root@host4 ~]# dnf -y install httpd

Webサーバー設定

Webサーバー設定

[root@host4 ~]# vi /etc/httpd/conf/httpd.conf ← httpd設定ファイル編集
#ServerName www.example.com:80
↓
ServerName sudachi.jp:80 ← サーバー名を指定

<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks
  ↓
    Options Includes ExecCGI FollowSymLinks ← CGI,SSIの許可

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None
  ↓
    AllowOverride All ← .htaccessの許可

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ← 長すぎるURI(414エラー)はログに記録しない

#
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
SetEnvIf Request_URI "default\.ida" no_log ← 追加(wormからのアクセスをログに記録しない)
SetEnvIf Request_URI "cmd\.exe" no_log ← 〃
SetEnvIf Request_URI "root\.exe" no_log ← 〃
SetEnvIf Request_URI "Admin\.dll" no_log ← 〃
SetEnvIf Request_URI "NULL\.IDA" no_log ← 〃
SetEnvIf Remote_Addr 192.168.1 no_log ← 追加(内部からのアクセスをログに記録しない)
SetEnvIf Remote_Addr 127.0.0.1 no_log ← 追加(自ホストからのアクセスをログに記録しない)
CustomLog logs/access_log combined env=!no_log ← 上記以外のアクセスをログに記録する

AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8 ← コメントアウト(文字化け対応)

#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl .rb ← CGIスクリプトに.plと.rbを追加


[root@host4 ~]# vi /etc/httpd/conf.d/autoindex.conf ← autoindex設定ファイル編集
<Directory "/usr/share/httpd/icons">
    Options MultiViews ← iconsディレクトリのファイル一覧を表示しないようにする
    AllowOverride None
    Require all granted
</Directory>

テストページ削除

[root@host4 ~]# rm -f /etc/httpd/conf.d/welcome.conf

Perlコマンドへ/usr/local/bin/perlでもアクセスできるようにする。

[root@host4 ~]# ln -s /usr/bin/perl /usr/local/bin/perl ← /usr/local/bin/perlから/usr/bin/perlへリンクをはる

[root@host4 ~]# whereis perl ← Perlのパスを確認
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz ← Perlのパスに/usr/local/bin/perlが表示されることを確認

ドキュメントルート所有者変更

[root@host4 ~]# chown sysop. /var/www/html/ ← ドキュメントルート所有者を変更

[root@host4 ~]# ll /var/www/ ← ドキュメントルート所有者変更確認
合計 0
drwxr-xr-x 2 root  root  6 11月 20 06:43 cgi-bin
drwxr-xr-x 2 sysop sysop 6  6月 10  2014 html

「httpd.conf」の文法チェック

[root@host4 ~]# apachectl configtest
Syntax OK

Webサーバー起動

[root@host4 ~]# systemctl start httpd ← httpd起動

[root@host4 ~]# systemctl enable httpd ← httpd自動起動設定
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

操作確認

[root@host4 ~]# systemctl status httpd
 httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-03-08 13:06:57 JST; 1min 16s ago
     Docs: man:httpd.service(8)
 Main PID: 6509 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 26213)
   Memory: 43.1M
   CGroup: /system.slice/httpd.service
           tq6509 /usr/sbin/httpd -DFOREGROUND
           tq6510 /usr/sbin/httpd -DFOREGROUND
           tq6511 /usr/sbin/httpd -DFOREGROUND
           tq6512 /usr/sbin/httpd -DFOREGROUND
           mq6513 /usr/sbin/httpd -DFOREGROUND

 3月 08 13:06:57 host3.sudachi.jp systemd[1]: Starting The Apache HTTP Server...
 3月 08 13:06:57 host3.sudachi.jp systemd[1]: Started The Apache HTTP Server.
 3月 08 13:06:57 host3.sudachi.jp httpd[6509]: Server configured, listening on: port 80