nginx安装upload和MD5,echo模块

简介:

由于工作需要,需要写一个可以自动升级的脚本来上报设备的一些基本信息,前期是每次都去下文件来做比较后去升级脚本,这样比较浪费流量,所以想到了在线上做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

相关文章
|
1月前
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
74 6
|
6天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
17 1
|
26天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
28 0
|
27天前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
43 1
|
28天前
|
网络协议 应用服务中间件 网络安全
linxu安装nginx
linxu安装nginx
64 0
|
1月前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
209 0
|
1月前
|
负载均衡 应用服务中间件 nginx
|
1月前
|
应用服务中间件 nginx Windows
windows下快速安装nginx 并配置开机自启动
windows下快速安装nginx 并配置开机自启动
windows下快速安装nginx 并配置开机自启动
|
23天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
27 0
|
1月前
|
应用服务中间件 nginx
Nginx中如何配置中文域名?
Nginx中如何配置中文域名?
41 0