0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NginxにModSecurityを適用

Last updated at Posted at 2025-04-28

NginxにModSecurityを導入するまで

インストール

sudo pacman -S libmodsecurity modsecurity-crs

Nginxへの適用

ModSecurityと依存関係のインストール

sudo pacman -Syu
sudo pacman -S git gcc pcre pcre2 zlib make

ModSecurityのダウンロードとビルド

git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git
git clone --depth 1 -b v3.0.13 https://github.com/SpiderLabs/ModSecurity
cd ModSecurity
git submodule init
git submodule update
./build.sh
./configure
make
sudo make install

nginxのソースコードのダウンロードとビルド

http://nginx.org/download/
ここより、最新のバージョンのnginxをダウンロードする
ここでもいいかも
http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-[latest nginx version].tar.gz
tar zxvf nginx-[latest nginx version].tar.gz
cd nginx-[latest nginx version]

./configure --with-compat --add-dynamic-module=../ModSecurity-nginx
make modules
sudo cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules

RuleSetをダウンロードと配置

wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v[latest version].tar.gz
tar -xzvf v[latest version].tar.gz

sudo mkdir -p /etc/nginx/modsec/coreruleset
sudo cp -r coreruleset-[latest version]/crs-setup.conf.example /etc/nginx/modsec/coreruleset/crs-setup.conf
sudo cp -r coreruleset-[latest version]/rules /etc/nginx/modsec/coreruleset/

必要なファイルのダウンロード

wget https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended -O /etc/nginx/modsec/modsecurity.conf
wget https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/unicode.mapping -O /etc/nginx/modsec/unicode.mapping

Nginx設定ファイルを編集

/etc/nginx/nginx.conf

load_module modules/ngx_http_modsecurity_module.so;

http {
    ...
    modsecurity on;
    modsecurity_rules_file /etc/nginx/modsec/modsecurity.conf;
    ...
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?