Skip to content

Instantly share code, notes, and snippets.

@knife0125
Last active August 30, 2022 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knife0125/5416748 to your computer and use it in GitHub Desktop.
Save knife0125/5416748 to your computer and use it in GitHub Desktop.

Apacheのインストールと設定

Apacheのインストール

インストール

# Apacheのインストール
yum install httpd -y

Apacheの起動と自動起動設定

# Apacheの起動
service httpd start

# Apacheの自動起動の設定
chkconfig httpd on

# 自動起動設定の確認
chkconfig httpd --list
    httpd              0:off	1:off	2:on	3:on	4:on	5:on	6:off

Apacheの設定

httpd.confのバックアップを作成

# httpd.confのオリジナルをバックアップ
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.origin

VirtualHostの設定

VirtualHostの有効化

# NameVirutalHostの有効化
vi /etc/httpd/conf/httpd.conf
    < #NameVirtualHost *:80
    > NameVirtualHost *:80

# 80番ポートをListenしていることの確認
    Listen 80

# 設置するバーチャルホストのconfファイルをIncludeするように追記
Include conf.userdefined/*.conf

VirtualHostのconfファイルを設置

# Documentを配置するディレクトリを準備
mkdir -p /var/www/example_dir
chown -R ユーザ名:ユーザ名 /var/www/example_dir

# バーチャルホストのconfファイルを作成
vi /etc/httpd/conf.userdefined/example_dir.conf
    <VirtualHost *:80>
        ServerName example.com
        DocumentRoot "/var/www/example_dir"
        DirectoryIndex index.html index.php
        ErrorLog /var/log/httpd/example_dir_error_log
        CustomLog /var/log/httpd/example_dir_access_log combined
        AddDefaultCharset UTF-8
        <Directory "/var/www/example_dir">
            AllowOverride All
        </Directory>
    </VirtualHost>

設定を反映

# 設定に問題がないかを確認
service httpd configtest

# Apacheを再起動して設定を反映
service httpd restart

基本的なセキュリティの設定

ServerSignatureの設定

これを設定する事で、Apacheのバージョン情報などがレスポンスのフッター情報に表示されないようにできる。

# ServerSignatureの設定をoffにする
vi /etc/httpd/conf/httpd.conf
    > ServerSignature Off

ServerTokensの設定

これを設定する事で、レスポンスヘッダにApacheバージョン情報などが表示されないようにできる。

# ServerTokensをProductOnlyに設定
vi /etc/httpd/conf/httpd.conf
    > ServerTokens Prod || ServerTokens ProductOnly

設定を反映

# 設定に問題がないかを確認
service httpd configtest

# Apacheを再起動して設定を反映
service httpd restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment