Skip to content

Commit 99047ca

Browse files
committed
update latest nginx
1 parent 1f8300e commit 99047ca

File tree

9 files changed

+163
-145
lines changed

9 files changed

+163
-145
lines changed

Dockerfile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,34 @@ FROM hyperknot/baseimage16:1.0.1
33
MAINTAINER friends@niiknow.org
44

55
ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 \
6-
TERM=xterm container=docker DEBIAN_FRONTEND=noninteractive \
7-
NGINX_VERSION=1.13.0-1~xenial
6+
TERM=xterm container=docker DEBIAN_FRONTEND=noninteractive
7+
8+
ADD ./build/nginx_1.13.1-1~xenial_amd64.deb /tmp
89

910
# start
1011
RUN \
1112
cd /tmp \
13+
1214
# add nginx repo
1315
&& curl -s https://nginx.org/keys/nginx_signing.key | apt-key add - \
1416
&& cp /etc/apt/sources.list /etc/apt/sources.list.bak \
1517
&& echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee -a /etc/apt/sources.list \
1618
&& echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee -a /etc/apt/sources.list \
1719

1820
# update repo, install nginx and module to get dependencies
19-
&& apt-get update -y && apt-get upgrade -y \
21+
&& apt-get update -y && apt-get upgrade -y --no-install-recommends --no-install-suggests \
2022
&& apt-get install -y --no-install-recommends --no-install-suggests \
21-
nano nginx=1.13.0-1~xenial \
22-
nginx-module-geoip=1.13.0-1~xenial \
23-
nginx-module-image-filter=1.13.0-1~xenial \
24-
gettext-base \
23+
nano libgd3 gettext-base unzip \
2524
&& dpkg --configure -a \
2625

26+
&& dpkg -i nginx_1.13.1-1~xenial_amd64.deb \
27+
2728
# re-enable all default services
2829
&& rm -f /etc/service/syslog-forwarder/down \
2930
&& rm -f /etc/service/cron/down \
3031
&& rm -f /etc/service/syslog-ng/down \
3132
&& rm -f /core \
3233

33-
# geoip stuff
34-
&& cd /tmp \
35-
&& curl http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | gzip -d - > /etc/nginx/GeoLiteCity.dat \
36-
3734
# forward request and error logs to docker log collector
3835
&& ln -sf /dev/stdout /var/log/nginx/access.log \
3936
&& ln -sf /dev/stderr /var/log/nginx/error.log \
@@ -42,13 +39,10 @@ RUN \
4239
# cleanup
4340
&& apt-get clean -y && apt-get autoclean -y \
4441
&& apt-get autoremove --purge -y \
45-
&& rm -rf /var/lib/apt/lists/* /var/lib/log/* /tmp/* /var/tmp/* \
46-
47-
# remove existing image filter module so we can overwrite with ours
48-
&& rm -rf /etc/nginx/modules/ngx_http_image_filter_m*.so
42+
&& rm -rf /var/lib/apt/lists/* /var/lib/log/* /tmp/* /var/tmp/*
4943

5044
ADD ./files /
51-
45+
5246
EXPOSE 80
5347

5448
CMD ["/sbin/my_init"]

build/Dockerfile

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,22 @@ FROM hyperknot/baseimage16:1.0.1
22

33
MAINTAINER friends@niiknow.org
44

5-
ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 TERM=xterm container=docker DEBIAN_FRONTEND=noninteractive NGINX_VERSION=1.13.0 NGINX_BUILD_DIR=/tmp/nginx
6-
ENV IMAGE_FILTER_URL=https://raw.githubusercontent.com/niiknow/docker-nginx-image-proxy/master/build/src/ngx_http_image_filter_module.c
5+
ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 \
6+
TERM=xterm container=docker DEBIAN_FRONTEND=noninteractive
77

8-
# start
9-
RUN \
10-
apt-get update && apt-get upgrade -y --force-yes --no-install-recommends \
11-
&& apt-get install -y --force-yes --no-install-recommends wget curl unzip nano vim apt-transport-https \
12-
apt-utils software-properties-common build-essential ca-certificates libssl-dev \
13-
zlib1g-dev dpkg-dev libpcre3 libpcre3-dev libgd-dev \
14-
15-
&& dpkg --configure -a \
16-
17-
# re-enable all default services
18-
&& rm -f /etc/service/syslog-forwarder/down \
19-
&& rm -f /etc/service/cron/down \
20-
&& rm -f /etc/service/syslog-ng/down \
21-
&& rm -f /core \
22-
&& wget -O - http://nginx.org/keys/nginx_signing.key | apt-key add - \
23-
&& cp /etc/apt/sources.list /etc/apt/sources.list.bak \
24-
&& echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee -a /etc/apt/sources.list \
25-
&& echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee -a /etc/apt/sources.list \
26-
&& apt-get update \
278

28-
# recompile nginx
29-
&& mkdir -p ${NGINX_BUILD_DIR} \
309

31-
# get the source
32-
&& cd ${NGINX_BUILD_DIR}; apt-get source nginx -y \
33-
&& mv ${NGINX_BUILD_DIR}/nginx-${NGINX_VERSION}/src/http/modules/ngx_http_image_filter_module.c ${NGINX_BUILD_DIR}/nginx-${NGINX_VERSION}/src/http/modules/ngx_http_image_filter_module.bak \
10+
ADD ./ubuntu.sh /tmp/
3411

35-
# apply patch
36-
&& curl -SL $IMAGE_FILTER_URL --output ${NGINX_BUILD_DIR}/nginx-${NGINX_VERSION}/src/http/modules/ngx_http_image_filter_module.c \
37-
&& sed -i "s/--with-http_ssl_module/--with-http_ssl_module --with-http_image_filter_module=dynamic/g" ${NGINX_BUILD_DIR}/nginx-${NGINX_VERSION}/debian/rules \
3812

39-
# get build dependencies
40-
&& cd ${NGINX_BUILD_DIR}; apt-get build-dep nginx -y \
41-
&& cd ${NGINX_BUILD_DIR}/nginx-${NGINX_VERSION}; dpkg-buildpackage -b \
42-
43-
# install new nginx package
44-
&& cd ${NGINX_BUILD_DIR}; dpkg -i nginx_${NGINX_VERSION}-1~xenial_amd64.deb
13+
# start
14+
RUN \
15+
cd /tmp \
16+
&& bash ubuntu.sh
4517

46-
ADD ./files /
18+
# docker run -it imageid /bin/bash
19+
# ftp passive
4720

48-
EXPOSE 80
21+
VOLUME ["/backup"]
4922

5023
CMD ["/sbin/my_init"]
778 KB
Binary file not shown.

build/src/ngx_http_image_filter_module.c

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define NGX_HTTP_IMAGE_GIF 2
3535
#define NGX_HTTP_IMAGE_PNG 3
3636
#define NGX_HTTP_IMAGE_WEBP 4
37+
#define NGX_HTTP_IMAGE_BMP 5
3738

3839

3940
#define NGX_HTTP_IMAGE_OFFSET_CENTER 0
@@ -58,15 +59,16 @@ typedef struct {
5859

5960
ngx_flag_t transparency;
6061
ngx_flag_t interlace;
62+
ngx_str_t output;
6163

62-
ngx_http_complex_value_t *wcv;
63-
ngx_http_complex_value_t *hcv;
64-
ngx_http_complex_value_t *oxcv;
65-
ngx_http_complex_value_t *oycv;
66-
ngx_http_complex_value_t *acv;
67-
ngx_http_complex_value_t *jqcv;
68-
ngx_http_complex_value_t *wqcv;
69-
ngx_http_complex_value_t *shcv;
64+
ngx_http_complex_value_t *wcv;
65+
ngx_http_complex_value_t *hcv;
66+
ngx_http_complex_value_t *oxcv;
67+
ngx_http_complex_value_t *oycv;
68+
ngx_http_complex_value_t *acv;
69+
ngx_http_complex_value_t *jqcv;
70+
ngx_http_complex_value_t *wqcv;
71+
ngx_http_complex_value_t *shcv;
7072

7173
size_t buffer_size;
7274
} ngx_http_image_filter_conf_t;
@@ -193,6 +195,13 @@ static ngx_command_t ngx_http_image_filter_commands[] = {
193195
0,
194196
NULL },
195197

198+
{ ngx_string("image_filter_output"),
199+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
200+
ngx_conf_set_str_slot,
201+
NGX_HTTP_LOC_CONF_OFFSET,
202+
offsetof(ngx_http_image_filter_conf_t, output),
203+
NULL },
204+
196205
ngx_null_command
197206
};
198207

@@ -236,7 +245,8 @@ static ngx_str_t ngx_http_image_types[] = {
236245
ngx_string("image/jpeg"),
237246
ngx_string("image/gif"),
238247
ngx_string("image/png"),
239-
ngx_string("image/webp")
248+
ngx_string("image/webp"),
249+
ngx_string("image/bmp")
240250
};
241251

242252

@@ -366,7 +376,19 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
366376
} else {
367377
ct = &ngx_http_image_types[ctx->type - 1];
368378
}
369-
379+
380+
if (ngx_strncmp(conf->output.data, "jpg", 3) == 0 || ngx_strncmp(conf->output.data, "jpeg", 4) == 0) {
381+
ct = &ngx_http_image_types[NGX_HTTP_IMAGE_JPEG - 1];
382+
} else if (ngx_strncmp(conf->output.data, "gif", 3) == 0){
383+
ct = &ngx_http_image_types[NGX_HTTP_IMAGE_GIF - 1];
384+
} else if (ngx_strncmp(conf->output.data, "png", 3) == 0){
385+
ct = &ngx_http_image_types[NGX_HTTP_IMAGE_PNG - 1];
386+
} else if (ngx_strncmp(conf->output.data, "webp", 4) == 0){
387+
ct = &ngx_http_image_types[NGX_HTTP_IMAGE_WEBP - 1];
388+
} else if (ngx_strncmp(conf->output.data, "bmp", 3) == 0){
389+
ct = &ngx_http_image_types[NGX_HTTP_IMAGE_BMP - 1];
390+
}
391+
370392
r->headers_out.content_type_len = ct->len;
371393
r->headers_out.content_type = *ct;
372394
r->headers_out.content_type_lowcase = NULL;
@@ -490,6 +512,10 @@ ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in)
490512
/* WebP */
491513

492514
return NGX_HTTP_IMAGE_WEBP;
515+
} else if (p[0] == 'B' && p[1] == 'M') {
516+
/* BMP */
517+
518+
return NGX_HTTP_IMAGE_BMP;
493519
}
494520

495521
return NGX_HTTP_IMAGE_NONE;
@@ -829,6 +855,16 @@ ngx_http_image_size(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
829855

830856
break;
831857

858+
case NGX_HTTP_IMAGE_BMP:
859+
if (ctx->length < 24) {
860+
return NGX_DECLINED;
861+
}
862+
863+
width = p[18] * 256 + p[19];
864+
height = p[22] * 256 + p[23];
865+
866+
break;
867+
832868
default:
833869

834870
return NGX_DECLINED;
@@ -1185,6 +1221,11 @@ ngx_http_image_source(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
11851221
#endif
11861222
break;
11871223

1224+
case NGX_HTTP_IMAGE_BMP:
1225+
img = gdImageCreateFromBmpPtr(ctx->length, ctx->image);
1226+
failed = "gdImageCreateFromBmpPtr() failed";
1227+
break;
1228+
11881229
default:
11891230
failed = "unknown image type";
11901231
break;
@@ -1237,11 +1278,23 @@ ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
12371278

12381279
out = NULL;
12391280

1281+
conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
1282+
1283+
if (ngx_strncmp(conf->output.data, "jpg", 3) == 0 || ngx_strncmp(conf->output.data, "jpeg", 4) == 0){
1284+
type = NGX_HTTP_IMAGE_JPEG;
1285+
} else if (ngx_strncmp(conf->output.data, "gif", 3) == 0){
1286+
type = NGX_HTTP_IMAGE_GIF;
1287+
} else if (ngx_strncmp(conf->output.data, "png", 3) == 0){
1288+
type = NGX_HTTP_IMAGE_PNG;
1289+
} else if (ngx_strncmp(conf->output.data, "webp", 4) == 0){
1290+
type = NGX_HTTP_IMAGE_WEBP;
1291+
} else if (ngx_strncmp(conf->output.data, "bmp", 3) == 0){
1292+
type = NGX_HTTP_IMAGE_BMP;
1293+
}
1294+
12401295
switch (type) {
12411296

12421297
case NGX_HTTP_IMAGE_JPEG:
1243-
conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
1244-
12451298
q = ngx_http_image_filter_get_value(r, conf->jqcv, conf->jpeg_quality);
12461299
if (q <= 0) {
12471300
return NULL;
@@ -1257,8 +1310,6 @@ ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
12571310
break;
12581311

12591312
case NGX_HTTP_IMAGE_PNG:
1260-
conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
1261-
12621313
if (conf->jpeg_quality >= 96) {
12631314
out = gdImagePngPtr(img, size);
12641315
failed = "gdImagePngPtr() failed";
@@ -1275,8 +1326,6 @@ ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
12751326

12761327
case NGX_HTTP_IMAGE_WEBP:
12771328
#if (NGX_HAVE_GD_WEBP)
1278-
conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
1279-
12801329
q = ngx_http_image_filter_get_value(r, conf->wqcv, conf->webp_quality);
12811330
if (q <= 0) {
12821331
return NULL;
@@ -1289,6 +1338,11 @@ ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
12891338
#endif
12901339
break;
12911340

1341+
case NGX_HTTP_IMAGE_BMP:
1342+
out = gdImageBmpPtr(img, size, 0);
1343+
failed = "gdImageBmpPtr() failed";
1344+
break;
1345+
12921346
default:
12931347
failed = "unknown image type";
12941348
break;
@@ -1459,6 +1513,8 @@ ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
14591513

14601514
ngx_conf_merge_value(conf->interlace, prev->interlace, 0);
14611515

1516+
ngx_conf_merge_str_value(conf->output, prev->output, "");
1517+
14621518
ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
14631519
1 * 1024 * 1024);
14641520

build/ubuntu.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
export NGINX_VERSION=1.13.1
4+
export IMAGE_FILTER_URL=https://gist.githubusercontent.com/noogen/4a662ade2d9570f8996f3af9869c5216/raw/54ff0a221a069a3c2574b0404afb71552fd4066d/ngx_http_image_filter_module.c
5+
export NGINX_BUILD_DIR=/usr/src/nginx/nginx-${NGINX_VERSION}
6+
7+
cd /tmp
8+
curl -s https://nginx.org/keys/nginx_signing.key | apt-key add -
9+
cp /etc/apt/sources.list /etc/apt/sources.list.bak
10+
echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee -a /etc/apt/sources.list
11+
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | tee -a /etc/apt/sources.list
12+
13+
apt-get update && apt-get upgrade -y --no-install-recommends --no-install-suggests
14+
apt-get install -y --no-install-recommends --no-install-suggests curl unzip nano vim apt-transport-https \
15+
apt-utils software-properties-common build-essential ca-certificates libssl-dev \
16+
zlib1g-dev dpkg-dev libpcre3 libpcre3-dev libgd-dev ftp
17+
18+
dpkg --configure -a
19+
20+
mkdir -p /usr/src/nginx
21+
22+
cd /usr/src/nginx
23+
apt-get source nginx=${NGINX_VERSION} -y
24+
mv ${NGINX_BUILD_DIR}/src/http/modules/ngx_http_image_filter_module.c ${NGINX_BUILD_DIR}/src/http/modules/ngx_http_image_filter_module.bak
25+
26+
curl -SL $IMAGE_FILTER_URL --output ${NGINX_BUILD_DIR}/src/http/modules/ngx_http_image_filter_module.c
27+
sed -i "s/--with-http_ssl_module/--with-http_ssl_module --with-http_image_filter_module/g" ${NGINX_BUILD_DIR}/debian/rules
28+
29+
cd /usr/src/nginx
30+
apt-get build-dep nginx -y
31+
cd ${NGINX_BUILD_DIR}
32+
dpkg-buildpackage -uc -us -b

files/etc/nginx/nginx.new

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
load_module "modules/ngx_http_image_filter_module.so";
2-
load_module "modules/ngx_http_geoip_module.so";
3-
load_module "modules/ngx_stream_geoip_module.so";
4-
51
# Server globals
62
user www-data;
73
worker_processes auto;
@@ -102,37 +98,9 @@ http {
10298
open_file_cache_min_uses 2;
10399
open_file_cache_errors off;
104100

105-
106101
# Other settings
107102
log_subrequest on;
108103
rewrite_log on;
109-
resolver 8.8.8.8 8.8.4.4;
110-
111-
112-
image_filter_buffer 20M;
113-
image_filter_interlace on;
114-
115-
# Needed to allow uri protocol slashes from being merged
116-
merge_slashes off;
117-
118-
119-
proxy_redirect off;
120-
proxy_set_header X-Real-IP $remote_addr;
121-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
122-
123-
proxy_pass_header Set-Cookie;
124-
proxy_connect_timeout 30s;
125-
proxy_send_timeout 30s;
126-
proxy_read_timeout 30s;
127-
proxy_ignore_headers Expires Cache-Control;
128-
proxy_temp_path /var/cache/nginx/temp;
129-
130-
131-
# Prevent Client headers from going to nginx.
132-
proxy_pass_request_headers off;
133-
134-
# GeoIP stuff
135-
geoip_city /etc/nginx/GeoLiteCity.dat;
136104

137105
# Wildcard include
138106
include /etc/nginx/conf.d/*.conf;

0 commit comments

Comments
 (0)