Skip to content

Commit 81d0fa4

Browse files
committed
🔀 🐛 🐳 💚 Merge Changes from the v3.1.2.
* 💚 Update CI. * 🐳 Fix dockerfile (#23) * 🐳 Create Dockerfile. #22 * 🐛 About the rule file permission check.
1 parent 9f5fa8e commit 81d0fa4

File tree

12 files changed

+304
-529
lines changed

12 files changed

+304
-529
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
name: test
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
- dev
8-
pull_request:
9-
branches:
10-
- master
11-
- dev
4+
- push
5+
- pull_request
126

137

148
jobs:
15-
test:
9+
docker:
10+
runs-on: ubuntu-latest
11+
needs: native
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
ref: ${{ github.ref }}
16+
- name: Build image with nginx:stable-alpine
17+
run: docker build -t test/nginx --build-arg=NGINX_VER=1.18.0 .
18+
native:
1619
runs-on: ubuntu-latest
1720
strategy:
1821
matrix:

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
inc/uthash
2-
.vscode
3-
docs/ZH-CN/html
2+
.vscode

CHANGES-ZH-CN.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@
1010

1111
***
1212

13-
## [v3.1.1] - 2021-01-18
13+
## [3.1.2] - 2021-02-17
1414

1515
### 修复
1616

17-
* 兼容较低版本的 GCC([becbbe0](https://github.com/ADD-SP/ngx_waf/commit/becbbe022b9f6efa606e720d7cbcd6c5d6f22c33))。
17+
* 修复了一个 bug,这个 bug 会导致当规则文件不具有可写权限时初始化失败([20acd27](https://github.com/ADD-SP/ngx_waf/commit/20acd27815d1f266d89c1557e93848c96117b8ff))。
18+
19+
***
20+
21+
## [3.1.1] - 2021-01-18
1822

23+
### 修复
24+
25+
* 兼容较低版本的 GCC([becbbe0](https://github.com/ADD-SP/ngx_waf/commit/becbbe022b9f6efa606e720d7cbcd6c5d6f22c33))。
1926

2027
***
2128

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
### Fixed
1010

1111

12+
***
13+
14+
## [3.1.2] - 2021-01-18
15+
16+
### Fixed
17+
18+
* Fixed a bug that caused module initialization to fail when the rule file was not writable ([20acd27](https://github.com/ADD-SP/ngx_waf/commit/20acd27815d1f266d89c1557e93848c96117b8ff)).
19+
1220
***
1321

1422
## [3.1.1] - 2021-01-18

Dockerfile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
FROM nginx:stable-alpine as builder
2+
ARG CHANGE_SOURCE=false
3+
ARG NGINX_VER=1.18.0
4+
5+
WORKDIR /usr/local/src
6+
COPY . ./ngx_waf
7+
8+
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
9+
## DOCKER_BUILDKIT=1 docker build -t test/nginx --build-arg=NGINX_VER=1.18.0 --build-arg=CHANGE_SOURCE=true .
10+
RUN set -xe \
11+
## If you're in China, or you need to change sources, will be set CHANGE_SOURCE to true in .env.
12+
&& if [ ${CHANGE_SOURCE} = true ]; then \
13+
# Change application source from dl-cdn.alpinelinux.org to aliyun source
14+
# ssed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
15+
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories \
16+
;fi \
17+
&& apk update \
18+
&& apk --no-cache --virtual add uthash-dev \
19+
gcc \
20+
libc-dev \
21+
make \
22+
openssl-dev \
23+
pcre-dev \
24+
zlib-dev \
25+
linux-headers \
26+
curl \
27+
gnupg \
28+
libxslt-dev \
29+
gd-dev \
30+
geoip-dev
31+
RUN set -xe \
32+
&& wget "https://nginx.org/download/nginx-${NGINX_VER}.tar.gz" -O "nginx-${NGINX_VER}.tar.gz" \
33+
&& tar -zxf "nginx-${NGINX_VER}.tar.gz" \
34+
&& cd "nginx-${NGINX_VER}" \
35+
&& ./configure \
36+
--prefix=/etc/nginx \
37+
--sbin-path=/usr/sbin/nginx \
38+
--modules-path=/usr/lib/nginx/modules \
39+
--conf-path=/etc/nginx/nginx.conf \
40+
--error-log-path=/var/log/nginx/error.log \
41+
--http-log-path=/var/log/nginx/access.log \
42+
--pid-path=/var/run/nginx.pid \
43+
--lock-path=/var/run/nginx.lock \
44+
--http-client-body-temp-path=/var/cache/nginx/client_temp \
45+
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
46+
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
47+
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
48+
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
49+
--with-perl_modules_path=/usr/lib/perl5/vendor_perl \
50+
--user=nginx \
51+
--group=nginx \
52+
--with-compat \
53+
--with-file-aio \
54+
--with-threads \
55+
--with-http_addition_module \
56+
--with-http_auth_request_module \
57+
--with-http_dav_module \
58+
--with-http_flv_module \
59+
--with-http_gunzip_module \
60+
--with-http_gzip_static_module \
61+
--with-http_mp4_module \
62+
--with-http_random_index_module \
63+
--with-http_realip_module \
64+
--with-http_secure_link_module \
65+
--with-http_slice_module \
66+
--with-http_ssl_module \
67+
--with-http_stub_status_module \
68+
--with-http_sub_module \
69+
--with-http_v2_module \
70+
--with-mail \
71+
--with-mail_ssl_module \
72+
--with-stream \
73+
--with-stream_realip_module \
74+
--with-stream_ssl_module \
75+
--with-stream_ssl_preread_module \
76+
--with-cc-opt='-Os -fomit-frame-pointer' \
77+
--with-ld-opt=-Wl,--as-needed \
78+
--add-module=/usr/local/src/ngx_waf \
79+
&& make \
80+
&& cp objs/nginx /usr/sbin/nginx
81+
82+
FROM nginx:stable-alpine
83+
COPY --from=builder /usr/sbin/nginx /usr/sbin/

README-ZH-CN.md

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -42,84 +42,7 @@
4242

4343
## 安装
4444

45-
On Unix Like
46-
47-
### 下载 nginx 源码
48-
49-
nginx 添加新的模块必须要重新编译,所以先[下载 nginx 源码](http://nginx.org/en/download.html)
50-
51-
```bash
52-
cd /usr/local/src
53-
wget http://nginx.org/download/nginx-version.tar.gz
54-
tar -zxf nginx-version.tar.gz
55-
```
56-
57-
> 推荐使用 nginx-1.18.0 的源码,若使用低版本的 nginx 源码则不保证本模块可以正常使用。本模块对 Mainline 版本的 nginx 做了兼容性处理,但考虑到 Mainline 版本仍在开发中,所以不保证一直可以兼容。如果遇到了兼容性问题请提 issue。
58-
59-
### 下载 ngx-waf 源码
60-
61-
```bash
62-
cd /usr/local/src
63-
git clone https://github.com/ADD-SP/ngx_waf.git
64-
cd ngx_waf
65-
```
66-
67-
### 编译和安装模块
68-
69-
从 nginx-1.9.11 开始,nginx 开始支持动态模块。
70-
71-
静态模块将所有模块编译进一个二进制文件中,所以增删改模块都需要重新编译 nginx 并替换。
72-
73-
动态模块则动态加载 `.so` 文件,无需重新编译整个 nginx。只需要将模块编译成 `.so` 文件然后修改`nginx.conf`即可加载对应的模块。
74-
75-
***
76-
77-
**使用静态模块**
78-
79-
```bash
80-
cd /usr/local/src/nginx-version
81-
./configure xxxxxx --add-module=/usr/local/src/ngx_waf
82-
make
83-
```
84-
> xxxxxx 为其它的编译参数,一般来说是将 xxxxxx 替换为`nginx -V`显示的编译参数。
85-
86-
如果您已经安装了 nginx 则可以直接替换二进制文件(假设原有的二进制文件的全路径为`/usr/local/nginx/sbin/nginx`
87-
88-
```bash
89-
nginx -s stop
90-
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
91-
cp objs/nginx /usr/local/nginx/sbin/nginx
92-
nginx
93-
```
94-
95-
> 如果不想中断 nginx 服务则可以通过热部署的方式来实现升级,热部署方法见[官方文档](https://nginx.org/en/docs/control.html)
96-
97-
如果您之前没有安装则直接执行下列命令
98-
```bash
99-
make install
100-
```
101-
102-
***
103-
104-
**使用动态模块**
105-
106-
```bash
107-
cd /usr/local/src/nginx-version
108-
./configure xxxxxx --add-dynamic-module=/usr/local/src/ngx_waf
109-
make modules
110-
```
111-
> xxxxxx 为其它的编译参数,一般来说是将 xxxxxx 替换为`nginx -V`显示的编译参数。
112-
113-
此时你需要找到一个目录用来存放模块的 .so 文件,本文假设存储在`/usr/local/nginx/modules`
114-
115-
```bash
116-
cp objs/ngx_http_waf_module.so /usr/local/nginx/modules/ngx_http_waf_module.so
117-
```
118-
119-
然后修改`nginx.conf`,在最顶部添加一行。
120-
```text
121-
load_module "/usr/local/nginx/modules/ngx_http_waf_module.so";
122-
```
45+
您可以使用两种方式安装本模块,详见[安装指南](docs/install-zh-cn.md)
12346

12447
## 使用
12548

@@ -266,20 +189,6 @@ https://example.com/www.bak
266189
2020/01/20 22:58:40 [alert] 24678#0: *11 ngx_waf: [BLACK-POST][(?i)(?:select.+(?:from|limit))], client: 192.168.1.1, server: example.com, request: "POST /xmlrpc.php HTTP/1.1", host: "example.com", referrer: "https://example.com/"
267190
```
268191

269-
## 开发文档
270-
271-
### 安装依赖
272-
273-
请确保已经安装 `doxygen``graphviz`,且 `doxygen` 的版本至少要为 1.8.17。
274-
275-
### 生成文档
276-
277-
```bash
278-
./mkdocs.sh
279-
```
280-
281-
`docs/ZH-CN/html` 目录下会生成开发文档。你可以直接用浏览器打开 `docs/ZH-CN/html/index.html` 文件来浏览文档。
282-
283192
## 开源许可证
284193

285194
[BSD 3-Clause License](LICENSE)

README.md

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,85 +43,7 @@ A web application firewall module for nginx without complex configuration.
4343

4444
## Install
4545

46-
On Unix Like
47-
48-
### download the source code of nginx
49-
50-
If you want to add a new nginx module, you'll need the nginx source code
51-
52-
```bash
53-
cd /usr/local/src
54-
wget http://nginx.org/download/nginx-1.18.0.tar.gz
55-
tar -zxf nginx-1.18.0.tar.gz
56-
```
57-
> The nginx-1.18.0 source code is recommended, but using a lower version of the nginx source code does not guarantee that this module will work. This module is compatible with the Mainline version of nginx, but since the Mainline version is still under development, there is no guarantee that it will always work. If you encounter compatibility issues, please create an issue.
58-
59-
### download the source code of ngx_waf
60-
61-
```bash
62-
cd /usr/local/src
63-
git clone https://github.com/ADD-SP/ngx_waf.git
64-
cd ngx_waf
65-
```
66-
67-
### compile and install
68-
69-
Starting from nginx-1.9.11, nginx began to support dynamic modules.
70-
71-
Using static modules requires all modules to be compiled into binary files, so adding, deleting and updating modules requires recompiling nginx and replacing the old binary files.
72-
73-
Using dynamic modules only needs to load the `.so` at runtime, without recompiling the entire nginx. Just compile the module into a `.so`, and then edit `nginx.conf` to load the corresponding module.
74-
75-
***
76-
77-
**use static modules**
78-
79-
```bash
80-
cd /usr/local/src/nginx-1.18.0
81-
./configure xxx --add-module=/usr/local/src/ngx_waf
82-
make
83-
```
84-
> If you have already installed nginx, it is recommended to run `nginx -V` to get the compilation parameters, and then replace `xxx` with it.
85-
86-
```bash
87-
nginx -s stop
88-
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
89-
cp objs/nginx /usr/local/nginx/sbin/nginx
90-
nginx
91-
```
92-
93-
> If you don’t want to stop the nginx service, you can upgrade through hot deployment, see [Official Document](https://nginx.org/en/docs/control.html) for hot deployment method.
94-
95-
96-
If nginx is not installed.
97-
98-
```bash
99-
make install
100-
```
101-
102-
***
103-
104-
**use dynamic modules**
105-
106-
```bash
107-
cd /usr/local/src/nginx-1.18.0
108-
./configure xxx --add-dynamic-module=/usr/local/src/ngx_waf
109-
make modules
110-
```
111-
> If you have already installed nginx, it is recommended to run `nginx -V` to get the compilation parameters, and then replace `xxx` with it.
112-
113-
Now you need to find a directory to store the `.so` file of the module, this doc assumes it is stored under `/usr/local/nginx/modules`
114-
115-
```bash
116-
cp objs/ngx_http_waf_module.so /usr/local/nginx/modules/ngx_http_waf_module.so
117-
```
118-
119-
Then edit `nginx.conf` and add a line at the top.
120-
121-
```text
122-
load_module "/usr/local/nginx/modules/ngx_http_waf_module.so";
123-
```
124-
46+
There are two ways to install this module, see [Installation Guide](docs/install.md).
12547

12648
## How to use?
12749

docs/ZH-CN/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)