非常教程

Nginx参考手册

ngx_http_secure_link_module

ngx_http_secure_link_module

  • 指令
  • secure_link
  • secure_link_md5
  • secure_link_secret
  • 嵌入式变量

ngx_http_secure_link_module模块(0.7.18)用于检查请求链接的真伪,保护资源免受未经授权的访问,并限制连杆的寿命。

请求链接的真实性通过将请求中传递的校验和值与为请求计算的值进行比较来验证。如果链接的使用期限有限并且时间已过,则认为链接已过期。这些检查的状态在$secure_link变量中可用。

该模块提供了两种替代操作模式。第一种模式由secure_link_secret指令启用,用于检查请求的链接的真实性,并保护资源免受未经授权的访问。第二种模式(0.8.50)由secure_link和secure_link_md5指令启用,也用于限制链接的生存期。

该模块不是默认生成的,它应该使用--with-http_secure_link_module配置参数启用。

指令

句法:

secure_link表达式;

默认:

语境:

http,服务器,位置

定义一个带有变量的字符串,从中提取链接的校验值和生存期。

一个 expression中使用的变量通常与请求相关联; 看下面的例子。

从字符串中提取的校验和值与由secure_link_md5指令定义的表达式的MD5哈希值进行比较。如果校验和不同,则该$secure_link变量设置为空字符串。如果校验和相同,则检查链路使用寿命。如果链接的使用期限有限且时间已过,则该$secure_link变量设置为“ 0”。否则,它被设置为“ 1”。在请求中传递的MD5哈希值以base64url编码。

如果链接有有限的生命周期,则自Epoch开始,以秒为单位设置截止时间(周四,1970年1月1日00:00:00 GMT)。该值在MD5散列之后的表达式中指定,并用逗号分隔。在请求中传递的到期时间可通过$secure_link_expires变量在secure_link_md5指令中使用。如果未指定到期时间,则链接具有无限的使用期限。

句法:

secure_link_md5表达式;

默认:

语境:

http,服务器,位置

定义一个表达式,MD5哈希值将被计算并与请求中传递的值进行比较。

表达式应包含链接(资源)的安全部分和秘密成分。如果链接的生命周期有限,则表达式还应该包含$secure_link_expires

为了防止未经授权的访问,表达式可能包含有关客户端的一些信息,例如其地址和浏览器版本。

例:

location /s/ {
    secure_link $arg_md5,$arg_expires;
    secure_link_md5 "$secure_link_expires$uri$remote_addr secret";

    if ($secure_link = "") {
        return 403;
    }

    if ($secure_link = "0") {
        return 410;
    }

    ...
}

/s/link?md5=_e4Nc3iduzkWRm01TBBNYw&expires=2147483647”链接限制/s/linkIP地址为127.0.0.1的客户端访问“ ”。该链接还具有有限的使用期限,直到2038年1月19日(格林威治标准时间)。

在UNIX上,md5请求参数值可以通过以下方式获得:

echo -n '2147483647/s/link127.0.0.1 secret' | \
    openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =

句法:

secure_link_secret word;

默认:

语境:

位置

定义word用于检查请求的链接的真实性的秘密。

请求链接的完整URI如下所示:

/prefix/hash/link

其中hash是为连接链接和秘密词计算的MD5哈希值的十六进制表示形式,并且prefix是不带斜杠的任意字符串。

如果请求的链接通过了真实性检查,则该$secure_link变量将设置为从请求URI中提取的链接。否则,该$secure_link变量将设置为空字符串。

例:

location /p/ {
    secure_link_secret secret;

    if ($secure_link = "") {
        return 403;
    }

    rewrite ^ /secure/$secure_link;
}

location /secure/ {
    internal;
}

/p/5e814704a28d9bc1914ff19fa0c4a00a/link” 的请求将被内部重定向到“ /secure/link”。

在UNIX上,此示例的哈希值可以通过以下方式获得:

echo -n 'linksecret' | openssl md5 -hex

嵌入式变量

$secure_link链接检查的状态。具体值取决于所选的操作模式。$secure_link_expires在请求中传递的链接的生命周期; 旨在仅在secure_link_md5指令中使用。

ngx_http_secure_link_module
Nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。

主页 https://nginx.org/
源码 http://hg.nginx.org/nginx
发布版本 1.13.6

Nginx目录

1.指南 | Guides
2.核心 | Core
3.ngx_google_perftools_module
4.ngx_http_access_module
5.ngx_http_addition_module
6.ngx_http_api_module
7.ngx_http_auth_basic_module
8.ngx_http_auth_jwt_module
9.ngx_http_auth_request_module
10.ngx_http_autoindex_module
11.ngx_http_browser_module
12.ngx_http_charset_module
13.ngx_http_core_module
14.ngx_http_dav_module
15.ngx_http_empty_gif_module
16.ngx_http_f4f_module
17.ngx_http_fastcgi_module
18.ngx_http_flv_module
19.ngx_http_geoip_module
20.ngx_http_geo_module
21.ngx_http_gunzip_module
22.ngx_http_gzip_module
23.ngx_http_gzip_static_module
24.ngx_http_headers_module
25.ngx_http_hls_module
26.ngx_http_image_filter_module
27.ngx_http_index_module
28.ngx_http_js_module
29.ngx_http_keyval_module
30.ngx_http_limit_conn_module
31.ngx_http_limit_req_module
32.ngx_http_log_module
33.ngx_http_map_module
34.ngx_http_memcached_module
35.ngx_http_mirror_module
36.ngx_http_mp4_module
37.ngx_http_perl_module
38.ngx_http_proxy_module
39.ngx_http_random_index_module
40.ngx_http_realip_module
41.ngx_http_referer_module
42.ngx_http_rewrite_module
43.ngx_http_scgi_module
44.ngx_http_secure_link_module
45.ngx_http_session_log_module
46.ngx_http_slice_module
47.ngx_http_spdy_module
48.ngx_http_split_clients_module
49.ngx_http_ssi_module
50.ngx_http_ssl_module
51.ngx_http_status_module
52.ngx_http_stub_status_module
53.ngx_http_sub_module
54.ngx_http_upstream_conf_module
55.ngx_http_upstream_hc_module
56.ngx_http_upstream_module
57.ngx_http_userid_module
58.ngx_http_uwsgi_module
59.ngx_http_v2_module
60.ngx_http_xslt_module
61.ngx_mail_auth_http_module
62.ngx_mail_core_module
63.ngx_mail_imap_module
64.ngx_mail_pop3_module
65.ngx_mail_proxy_module
66.ngx_mail_smtp_module
67.ngx_mail_ssl_module
68.ngx_stream_access_module
69.ngx_stream_core_module
70.ngx_stream_geoip_module
71.ngx_stream_geo_module
72.ngx_stream_js_module
73.ngx_stream_limit_conn_module
74.ngx_stream_log_module
75.ngx_stream_map_module
76.ngx_stream_proxy_module
77.ngx_stream_realip_module
78.ngx_stream_return_module
79.ngx_stream_split_clients_module
80.ngx_stream_ssl_module
81.ngx_stream_ssl_preread_module
82.ngx_stream_upstream_hc_module
83.ngx_stream_upstream_module