由于工作需要,需要写一个可以自动升级的脚本来上报设备的一些基本信息,前期是每次都去下文件来做比较后去升级脚本,这样比较浪费流量,所以想到了在线上做MD5校验然后再决定是否需要下载脚本来升级,所以在网上查了下nginx关于md5校验配置;
由于nginx不支持MD5模块,echo模块,上传和下载模块,所以需要下载安装,步骤如下:
下载nginx和相关模块:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
mkdir
/package
cd
/package
wget http:
//nginx
.org
/download/nginx-1
.8.1.
tar
.gz
wget -O filr-md5-master.zip https:
//github
.com
/cfsego/file-md5/archive/master
.zip
wget http:
//nchc
.dl.sourceforge.net
/project/pcre/pcre/8
.37
/pcre-8
.37.
tar
.gz
wget http:
//prdownloads
.sourceforge.net
/libpng/zlib-1
.2.11.
tar
.gz
wget wget https:
//github
.com
/openresty/echo-nginx-module/archive/v0
.60.
tar
.gz
tar
xf nginx-1.8.1.
tar
.gz
unzip filr-md5-master.zip
tar
xf pcre-8.37.
tar
.gz
tar
xf zlib-1.2.11.
tar
.gz
tar
xf v0.60.
tar
.gz
然后安装nginx,已安装的安装下模块就好
如果没有下载到可以到我的云地址去下载
https:
//pan
.baidu.com
/s/1o9tvhkm
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
cd
/package/nginx-1
.8.1/
.
/configure
--prefix=
/usr/local/nginx
\
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre --with-http_realip_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-pcre=
/package/pcre-8
.37 \
--with-zlib=
/package/zlib-1
.2.11 \
--add-module=
/package/echo-nginx-module-0
.60 \
--add-module=
/package/file-md5-master
\
--add-module=
/package/nginx-upload-module-2
.2 \
--with-http_secure_link_module
make
&&
make
install
|
如果在安装的时候缺少什么包直接yum安装就好了
然后开始配置nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
mkdir -p /usr/local/nginx/html/test
echo testFile >/usr/local/nginx/html/test/testFile
server {
listen 80;
server_name localhost;
root html;
location /test {
add_header Content-MD5 $file_md5;
}
/usr/local/nginx/sbin/nginx -s reload
这样直接访问
[root@hxy nginx]# curl -I localhost/test/testFile
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Tue, 09 Jan 2018 06:15:59 GMT
Content-Type: text/plain
Content-Length: 9
Last-Modified: Tue, 09 Jan 2018 06:15:54 GMT
Connection: keep-alive
ETag:
"5a545e1a-9"
Content-MD5: d43a6ecaa892a1962398ac9170ea9bf2
Accept-Ranges: bytes
就能出MD5了
还有就是直接访问就能出MD5的需要echo
http {
server {
listen 80;
server_name localhost;
root html;
location /test {
# add_header Content-MD5 $file_md5;
if
( $arg_md5 ~*
"true"
)
{
echo $file_md5;
}
}
}
}
/usr/local/nginx/sbin/nginx -s reload
|
然后查看下结果
1
2
|
# curl localhost/test/testFile?md5=true
d43a6ecaa892a1962398ac9170ea9bf2
|
这就是文件的MD5值了
本文转自 Forande 51CTO博客,原文链接:http://blog.51cto.com/853056088/2059229