Apache導入

1.httpdインストール

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

2.Webサーバー設定

httpd.conf修正

[root@miracle ~]# vi /etc/httpd/conf/httpd.conf

ServerName miracle-serv.website:80

# 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.10 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を追加

autoindex.conf修正

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

3.テストページ削除

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

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

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

[root@miracle ~]# whereis perl ← Perlのパスを確認
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz

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

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

[root@miracle ~]# ll /var/www/
合計 8
drwxr-xr-x. 2 root     root     4096  8月 29 04:16 cgi-bin
drwxr-xr-x. 2 neko     neko     4096  8月 29 04:16 html

6.httpd.confのチェック

[root@miracle ~]# apachectl configtest
Syntax OK

7.Webサーバー起動

[root@miracle ~]# systemctl start httpd

8.Webサーバー自動起動設定

[root@miracle ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

9.動作状況確認

[root@miracle ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset:>
   Active: active (running) since Tue 2022-09-13 19:15:17 EDT; 1min 20s ago
     Docs: man:httpd.service(8)
 Main PID: 59978 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 11378)
   Memory: 36.6M
   CGroup: /system.slice/httpd.service
           ├─59978 /usr/sbin/httpd -DFOREGROUND
           ├─59979 /usr/sbin/httpd -DFOREGROUND
           ├─59980 /usr/sbin/httpd -DFOREGROUND
           ├─59981 /usr/sbin/httpd -DFOREGROUND
           └─59982 /usr/sbin/httpd -DFOREGROUND

 9月 13 19:15:17 miracle systemd[1]: Starting The Apache HTTP Server...
 9月 13 19:15:17 miracle systemd[1]: Started The Apache HTTP Server.
 9月 13 19:15:17 miracle httpd[59978]: Server configured, listening on: port 80

10.ポート開放

①ルーター設定
 TCP80番ポートの設定をしてください。
 ルーターの設定は各ルーターのマニュアルを参照してください。
 こんな便利なサイトもありますので、参考にしましょう⇒メーカー別ルーターポート開放手順

このポート開放はPPPoEルータで行います。

②iptables設定
 サーバー側のファイアウォール設定で、TCP80番ポートへのアクセスを許可するようにする。
 ファイアウォール設定はこちらを参照

11.外部アクセスチェック

Portチェックテスト【外部からのPort開放確認】で「ホスト名(FQDN) または グローバルIPアドレス」にドメイン名、「チェックポート番号」に80、「無料で・・・」にチェックを入れて「Portチェック実行」ボタンを押下、下記の表示が出ればOK!

テストページを作成しチェック。

[root@miracle ~]# echo test >> /var/www/html/index.html

Website Testで「Enter URL」にドメイン名を入力し、「Test Now」ボタン押下、下記の様に表示されればOK!

テストページ削除

[root@miracle ~]# rm -f /var/www/html/index.html

コメント

タイトルとURLをコピーしました