-->

# Changing the following options will not really affect the security of the
# server, but might make attacks slightly more difficult in some cases.
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#ServerTokens Minimal
ServerTokens OS
#ServerTokens Full
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#ServerSignature Off
ServerSignature On
#
# Allow TRACE method
#
# Set to "extended" to also reflect the request body (only for testing and
# diagnostic purposes).
#
# Set to one of: On | Off | extended
TraceEnable Off
#TraceEnable On
# --- 情報漏洩対策 ---
# ヘッダー情報を最小限にする
ServerTokens Prod
# 画面上の署名を消す
ServerSignature Off
# 使用している言語を秘匿する
Header always unset "X-Powered-By"
# スニッフィング攻撃対策
# (ファイルの中身を勝手に推測して実行するのを禁止)
Header always set X-Content-Type-Options "nosniff"
# --- Denial of Service(DoS)攻撃対策 ---
# ブラウザ等からサーバーに送られてくるデータ容量を制限
# (巨大データ送信によるメモリ枯渇、ディスク容量枯渇の防止)
LimitRequestBody 10485760
# ブラウザ等からサーバーに送られてくるヘッダーの行数を制限
# (長いヘッダー情報送信によるメモリ枯渇、CPU枯渇の防止)
LimitRequestFields 50
# Slowloris攻撃対策
# (通信を意図的に遅延させたコネクション上限の枯渇を防止)
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
# Cross-Site Tracing (XST) 対策
# (TRACEリクエストを使ったcookie や認証ヘッダーの盗み取りを防止)
TraceEnable Off
# httpoxy脆弱性対策
# (HTTP_PROXYという環境変数を使った情報の盗み取りを防御)
RequestHeader unset Proxy
# 一度アクセスHTTPSにアクセスすると、その後6ヶ月間はHTTPSアクセスに強制
# (HTTPでアクセスされた瞬間に攻撃者が通信を傍受するのを阻止)
Header always set Strict-Transport-Security "max-age=15768000"
# 上記設定はHTTP通信でのテストが困難になるので、テスト段階ではこちら10分設定を推奨
#Header always set Strict-Transport-Security "max-age=600"
# --- Content-Security-Policy(CSP)設定 ---
# default-src設定 = 自分と同じドメインから配信されるファイルを許可
# https設定 = HTTPS通信から送られるデータは許可
# script-src設定 = 自サーバー内のJavaScript、またはHTML内のインラインと、テキストデータから変換されるJavaScriptを許可
# frame-ancestors設定 = 他人がiframeを使って自分のサイトを埋め込むのを禁止
Header always set Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval'; frame-ancestors 'self';"
#特定のボット(自動巡回プログラム)からのアクセスを禁止し、それ以外のすべてのアクセスを許可する
<Location />
#Go言語で作られたプログラムを拒否
SetEnvIf User-Agent "Go-http-client/1.1" denybot
#中国の検索エンジン「百度(Baidu)」のクローラーを拒否
SetEnvIf User-Agent "BaiduSpider" denybot
#カスタムされた自動通信プログラムを拒否
SetEnvIf User-Agent "Custom-AsyncHttpClient" denybot
#上で拒否設定したもの以外は全て認める
<RequireAll>
Require all Granted
Require not env denybot
</RequireAll>
</Location>
# --- ディレクトリ固有設定 ---
<Directory 「アクセス制限したいディレクトリのpath」>
# 意図しない設定上書きを防止。.htaccessを使ってる場合はこの設定はコメントアウトする必要がある。
AllowOverride None
# ファイル一覧出力の禁止(ファイル情報の秘匿)
# シンボリックリンク禁止(非公開ファイルへの不正アクセスを禁止)
Options -Indexes -FollowSymLinks
# GET, POST, HEAD 以外はすべて拒否
<LimitExcept GET POST HEAD>
Require all denied
</LimitExcept>
</Directory>
Header always set Content-Security-Policy "default-src 'self' *.a8ad.jp *.a8.net *.googlesyndication.com *.doubleclick.net *.google.com *.gstatic.com *.google-analytics.com *.googletagmanager.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' ajax.googleapis.com *.a8ad.jp *.a8.net *.googlesyndication.com *.doubleclick.net *.google.com *.gstatic.com *.google-analytics.com *.googletagmanager.com; img-src 'self' data: *.a8ad.jp *.a8.net *.googlesyndication.com *.doubleclick.net *.google.com *.gstatic.com *.google-analytics.com; frame-src 'self' *.a8ad.jp *.a8.net *.googlesyndication.com *.doubleclick.net *.google.com; connect-src 'self' *.googlesyndication.com *.doubleclick.net *.google.com *.adtrafficquality.google *.google-analytics.com; style-src 'self' 'unsafe-inline' *.googlesyndication.com *.google.com *.gstatic.com; font-src 'self' data: *.gstatic.com; frame-ancestors 'self';"

apache2ctl configtest
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
sudo a2enmod headers
sudo service apache2 restart