需求、现状:
1、公司用的是阿里云的机器
2、nginx是采用yum安装
3、需要给nginx添加mod_security模块
以下为简易安装步骤:
安装 #modsecurity安装 cd /home/haowenzhi/source wget -O modsecurity-2.9.1.tar.gz https://www.modsecurity.org/tarball/2.9.1/modsecurity-2.9.1.tar.gz tar -zxvf modsecurity-2.9.1.tar.gz cd modsecurity-2.9.1 chmod a+x ./autogen.sh ./configure --enable-standalone-module --disable-mlogc make #nginx编译二进制nginx文件 cd ../ wget http://nginx.org/download/nginx-1.10.1.tar.gz cd nginx-1.10.1 因为之前是nginx是yum安装的 nginx -V可以查看安装configure参数,这只是开发环境的,线上环境还是需要变化的 ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --add-module=/home/haowenzhi/source/modsecurity-2.9.1/nginx/modsecurity #千万不要make install 这样会直接覆盖现有的nginx二进制,为防止意外,需要备份原有的bin make 下载规则库 cd /home/haowenzhi/source/ git clone https://github.com/SpiderLabs/owasp-modsecurity-crs cp -R owasp-modsecurity-crs /etc/nginx/ mv owasp-modsecurity-crs/crs-setup.conf.example owasp-modsecurity-crs/crs-setup.conf 编写配置文件 vim /etc/nginx/modsecurity.conf #开启规则 SecRuleEngine On SecAuditLogFileMode 0550 SecAuditLogDirMode 0777 SecAuditLogStorageDir /var/log/nginx/modsecurity #新增规则 Include owasp-modsecurity-crs/crs-setup.conf Include owasp-modsecurity-crs/rules/*.conf vim /etc/nginx/vhosts/haowenzhi_phpfpm location / { root /home/haowenzhi/tengyue/webroot; rewrite ^(.*)?$ /_mvc_entry_point.php$1 break; fastcgi_pass 127.0.0.1:9016; fastcgi_index index.php; fastcgi_param TENGYUE_BASE_PATH "/home/haowenzhi/tengyue"; fastcgi_param TENGYUE_ENV development; fastcgi_param TENGYUE_ENV_TAG haowenzhi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; ModSecurity 配置 ModSecurityEnabled on; ModSecurityConfig /etc/nginx/modsecurity.conf; } cp /home/haowenzhi/source/modsecurity-2.9.1/modsecurity.conf-recommended /etc/nginx/modsecurity.conf cp /home/haowenzhi/source/modsecurity-2.9.1/unicode.mapping /etc/nginx/ service nginx stop cp /usr/sbin/nginx /usr/sbin/nginx_old cp objs/nginx /usr/sbin/nginx service nginx restart