由于工作需要,需要写一个可以自动升级的脚本来上报设备的一些基本信息,前期是每次都去下文件来做比较后去升级脚本,这样比较浪费流量,所以想到了在线上做MD5校验然后再决定是否需要下载脚本来升级,所以在网上查了下nginx关于md5校验配置;
由于nginx不支持MD5模块,echo模块,上传和下载模块,所以需要下载安装,步骤如下:
下载nginx和相关模块:
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
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
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
然后查看下结果
# curl localhost/test/testFile?md5=true d43a6ecaa892a1962398ac9170ea9bf2
这就是文件的MD5值了
可选的编译
./configure --prefix=/usr/local/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 \ --http-client-body-temp-path=/var/lib/nginx/tmp/client_body \ --http-proxy-temp-path=/var/lib/nginx/tmp/proxy \ --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \ --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \ --http-scgi-temp-path=/var/lib/nginx/tmp/scgi \ --pid-path=/run/nginx.pid \ --lock-path=/run/lock/subsys/nginx \ --user=nginx --group=nginx \ --with-http_auth_request_module \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_degradation_module \ --with-http_slice_module \ --with-http_stub_status_module \ --with-mail=dynamic \ --with-mail_ssl_module \ --with-pcre \ --with-pcre-jit \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-debug \ --add-module=/data/package/echo-nginx-module-0.60 \ --add-module=/data/package/file-md5-master
注释:
如果是nginx1.10以上的版本echo0.60版本在编译安装的时候就会报错,需要下载0.61的版本才会OK0.61的下载地址在下面
wget https://codeload.github.com/openresty/echo-nginx-module/tar.gz/v0.61
这个就是我在安装echo模块时的报错,别的都没问题,只要安装0.61就没问题了
转载于:https://blog.51cto.com/853056088/2059229