一、

server {
listen 8866;
server_name _;
access_log /usr/local/etc/nginx/log/download.access.log main;
error_log /usr/local/etc/nginx/log/download.error.log;
location / {
root /usr/local/etc/nginx/aruntestdir;
if ($request_filename ~* ^.*?\.(html|zip|gz)$){ #不能为空
add_header Content-Disposition: 'attachment;';
add_header Content-Type: 'APPLICATION/OCTET-STREAM';
}
}
}

测试:

如下图所示在nginx的返回的网页Respons中添加头字段.

Request头解释:

<1>$request_filename

file path for the current request, based on the root or alias directives, and the request URI

<2>Content-Disposition

    In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.
attachment (indicating it should be downloaded; most browsers presenting a 'Save as' dialog

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

<3>Content-Type

    The Content-Type entity header is used to indicate the media type of the resource.In responses, a Content-Type header tells the client what the content type of the returned content actually is.
application/octet-stream meaning "download this file" 扩展:
What are MIME types?
MIME types describe the media type of content either in email or served by web servers or web applications and are intended to help guide a web browser in how the content is to be processed and displayed. Examples of MIME types are: text/html for normal web pages
text/plain for plain text
text/css for Cascading Style Sheets
text/javascript for scripts
application/octet-stream meaning "download this file"
application/x-java-applet for Java applets
application/pdf for PDF documents

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type

二、附下载python脚本

#!/usr/bin/env python
import os
import urllib
def Schedule(blocks, blocksize, totalsizeofile):
"""
The third argument, if present, is a hook function that will be called once on establishment of the network connection
and once after each block read thereafter.
The third argument may be -1 on older FTP servers which do not return a file size in response to a retrieval request. The hook will be passed three arguments;
:param blocks: a count of blocks transferred so far
:param blocksize: a block size in bytes
:param totalsizeofile: the total size of the file.
:return:
"""
percent = 100.0 * blocks * blocksize / totalsizeofile
if percent > 100 :
percent = 100
print '%.2f %%' % percent
if __name__ == "__main__":
url = 'http://127.0.0.1:8088/downtest.html' #download url
local = os.path.join('/tmp','downtest.html') #local path + filename
#If no Content-Length header was supplied, urlretrieve() can not check the size of the data it has downloaded,
# and just returns it. In this case you just have to assume that the download was successful.
urllib.urlretrieve(url, local, Schedule)

032_nginx配置文件安全下载的更多相关文章

  1. 【学习总结】GirlsInAI ML-diary day-2-Python版本选取与Anaconda中环境配置与下载

    [学习总结]GirlsInAI ML-diary 总 原博github链接-day2 Python版本选取与Anaconda中环境配置与下载 1-查看当前Jupyter的Python版本 开始菜单选J ...

  2. Nginx 核心配置-作为下载服务器配置

    Nginx 核心配置-作为下载服务器配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.无限速版本的下载服务器 1>.查看主配置文件 [root@node101.yinz ...

  3. maven配置和下载

    下载链接:http://maven.apache.org/docs/ 以maven3.0.4为例,eclipse以kepler为例 环境变量的配置 1.系统变量-新建-变量名:MAVEN_HOME-变 ...

  4. WinDbg配置与下载 (转载)

    WinDbg配置和使用基础     WinDbg是微软发布的一款相当优秀的源码级(source-level)调试工具,可以用于Kernel模式调试和用户模式调试,还可以调试Dump文件. 1. Win ...

  5. NAS4Free 配置BT下载

    NAS4Free 9.3.0.2 开启BT下载功能 Services|BitTorrent 选中右上角的复选框 Peer port 是监听端口,用于接受外部连接,需要在路由器配置该端口到服务器,才能提 ...

  6. 在firefox的flashgot中配置各种下载器

    一.在firefox中安装flashgot下载管理器 flashgot是firefox的一个扩展,在联网的情况下,可以在firefox中的附加组件中搜索flashgot,然后安装. 二.在flashg ...

  7. appach-maven-3.5.0配置与下载

    今天需要搭建javaweb开发的环境,需要配置maven.弄了半天终于配置好了.蛋疼的一批.楼主用的是win10的系统.不知道Linux下的也是不是这么坑! 首先,需要把maven的包下载下来.进入h ...

  8. idea部署Maven入门(一)——环境变量的配置和下载

        介绍:       1  Maven是用来管理jar包的一种工具,       2  Maven主要是构建java项目和java web项目        3 maven项目管理所依赖的jar ...

  9. scrapy框架修改单个爬虫的配置,包括下载延时,下载超时设置

    在一个框架里面有多个爬虫时,每个爬虫的需求不相同,例如,延时的时间,所以可以在这里配置一下custom_settings = {},大括号里面写需要修改的配置,然后就能把settings里面的配置给覆 ...

随机推荐

  1. idea使用maven打包项目

    第一步:打开maven Projects 第二步.找到package 第三步,运行.到路径下面去找打包的文件吧. 第二种方法: 使用命令 cmd进入项目目录,例如项目在D盘项目名poject 输入: ...

  2. 【.Net平台下插件开发】-MEF与MAF初步调研

    背景   Team希望开发一个插件的平台去让某搜索引擎变得更好.主要用于采集一些不满意信息(DSAT)给Dev.这些信息会由不同的team提供不同的 tool分析.有的提供仅仅是一个website,有 ...

  3. overlay网络隔离实验失败记录

    按照 https://www.cnblogs.com/CloudMan6/p/7341487.html进行操作,实验结果与老师文章中的正好相反,不同 overlay 网络中的主机可以通信,验证部分见下 ...

  4. 当一些库和类无法在Silverlight工程中使用

    因为要更新空间数据,所以需要导入MDB文件.但是Silverlight中不能直接使用OdbcConnection类读取MDB文件,所以需要新建一个ASP.NET空Web应用程序 工程 随后在此工程中, ...

  5. vim学习之git for windows

    这是我在博客园的第二篇文章,今晚是在线的特殊日子,应小编的要求不想多讲,喝了点酒,感觉到压力和挑战性,抽了几根烟,现在有点飘飘欲仙的感觉.在长江大学11教的6楼,是长大在线的办公室,这个晚上总是不关灯 ...

  6. js动态修改Easyui元素不生效,EasyUI动态渲染解析解决方案

    easyui的渲染是在在网页加载完成后,相当于在$(document).ready()事件中,对整个网页进行了一次扫描,发现某个input标签含有easyui的属性,就在相应的地方进行ui的修改.因此 ...

  7. 使用 JS 实现图片左右跑马灯

    Ø  前言 之前写了一篇使用 JS 实现文字上下跑马灯,现在乘热打铁在把图片左右跑马灯一起贴出来,不多说直接看代码. 1.   首先定义 css 样式 <style type="tex ...

  8. C# 数据类型之 String(字符串)

    Ø  简介 在开发中最常见的数据类型就是 String 类型,即字符串类型.为什么要单独讨论下这个类型,是因为:它是系统内置的基础数据类型:它的使用频率非常高:它是一个特殊的引用类型.其实大家都会使用 ...

  9. 什么是CMD

    cmd是command的缩写.命令提示符是在操作系统中,提示进行命令输入的一种工作提示符.在不同的操作系统环境下,命令提示符各不相同. 在windows环境下,命令行程序为cmd.exe,是一个32位 ...

  10. react——获取数据ajax()、$.ajax()、fetch()、axios

    ajax() import React from 'react'; import ReactDom from 'react-dom'; import ajax from './tool.js'; cl ...