非常教程

Nginx参考手册

ngx_stream_ssl_module

ngx_stream_ssl_module

  • 示例配置
  • 指令
  • ssl_certificate
  • ssl_certificate_key
  • ssl_ciphers
  • ssl_client_certificate
  • ssl_crl
  • ssl_dhparam
  • ssl_ecdh_curve
  • ssl_handshake_timeout
  • ssl_password_file
  • ssl_prefer_server_ciphers
  • ssl_protocols
  • ssl_session_cache
  • ssl_session_ticket_key
  • ssl_session_tickets
  • ssl_session_timeout
  • ssl_trusted_certificate
  • ssl_verify_client
  • ssl_verify_depth
  • 嵌入式变量

所述ngx_stream_ssl_module模块(1.9.0)提供了一种用于流代理服务器与SSL / TLS协议工作必要的支持。该模块不是默认生成的,它应该使用--with-stream_ssl_module配置参数启用。

示例配置

为了减轻处理器的负担,建议

  • 设置工作进程的数量等于处理器的数量,
  • 启用共享会话缓存,
  • 禁用内置会话缓存,
  • 并可能增加会话生存期(默认为5分钟):
worker_processes auto;

stream {

    ...

    server {
        listen              12345 ssl;

        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
        ssl_certificate     /usr/local/nginx/conf/cert.pem;
        ssl_certificate_key /usr/local/nginx/conf/cert.key;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;

        ...
    }

指令

句法:

ssl_certificate文件;

默认:

语境:

流,服务器

指定一个file带有给定服务器的PEM格式的证书。如果除了主要证书之外还应指定中间证书,则应按照以下顺序在同一文件中指定它们:主要证书为先,然后为中间证书。PEM格式的密钥可以放在同一个文件中。

从版本1.11.0开始,可以多次指定此指令以加载不同类型的证书,例如RSA和ECDSA:

server {
    listen              12345 ssl;

    ssl_certificate     example.com.rsa.crt;
    ssl_certificate_key example.com.rsa.key;

    ssl_certificate     example.com.ecdsa.crt;
    ssl_certificate_key example.com.ecdsa.key;

    ...
}

只有OpenSSL 1.0.2或更高版本支持不同证书的单独证书链。对于旧版本,只能使用一个证书链。

句法:

ssl_certificate_key文件;

默认:

语境:

流,服务器

指定file给定服务器的PEM格式密钥。

enginenameid可以指定代替file,它加载了指定的密钥id由OpenSSL的引擎name

句法:

ssl_ciphers密码;

默认:

ssl_ciphers HIGH:!aNULL:!MD5;

语境:

流,服务器

指定启用的密码。密码以OpenSSL库理解的格式指定,例如:

ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

完整列表可以使用“ openssl ciphers”命令查看。

句法:

ssl_client_certificate文件;

默认:

语境:

流,服务器

指定file带有用于验证客户端证书的PEM格式的可信CA证书。

证书列表将发送给客户。如果不需要,可以使用ssl_trusted_certificate指令。

句法:

ssl_crl文件;

默认:

语境:

流,服务器

指定file用于验证客户端证书的PEM格式的带撤销证书(CRL)。

句法:

ssl_dhparam文件;

默认:

语境:

流,服务器

指定fileDHE密码的DH参数。

句法:

ssl_ecdh_curve曲线;

默认:

ssl_ecdh_curve auto;

语境:

流,服务器

指定一个curve用于ECDHE密码。

使用OpenSSL 1.0.2或更高版本时,可以指定多条曲线(1.11.0),例如:

ssl_ecdh_curve prime256v1:secp384r1;

特殊值auto(1.11.0)指示nginx在使用OpenSSL 1.0.2或更高prime256v1版本时使用内置于OpenSSL库中的列表,或使用旧版本。

在版本1.11.0之前,prime256v1曲线默认使用。

句法:

ssl_handshake_timeout时间;

默认:

ssl_handshake_timeout 60s;

语境:

流,服务器

指定完成SSL握手的超时。

句法:

ssl_password_file文件;

默认:

语境:

流,服务器

指定file密码的密码,其中每个密码在单独的行上指定。加载密钥时会依次尝试密码。

例:

stream {
    ssl_password_file /etc/keys/global.pass;
    ...

    server {
        listen 127.0.0.1:12345;
        ssl_certificate_key /etc/keys/first.key;
    }

    server {
        listen 127.0.0.1:12346;

        # named pipe can also be used instead of a file
        ssl_password_file /etc/keys/fifo;
        ssl_certificate_key /etc/keys/second.key;
    }
}

句法:

ssl_prefer_server_ciphers on | 关闭;

默认:

ssl_prefer_server_ciphers off;

语境:

流,服务器

指定在使用SSLv3和TLS协议时,服务器密码应优先于客户端密码。

句法:

ssl_protocols SSLv2 TLSv1 TLSv1.2;

默认:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

语境:

流,服务器

启用指定的协议。

仅当使用OpenSSL 1.0.1或更高版本时,TLSv1.1and TLSv1.2参数才起作用。TLSv1.3只有在使用支持TLSv1.3的OpenSSL 1.1.1时,参数(1.13.0)才有效。

句法:

ssl_session_cache off | none | 内建[:大小];

默认:

ssl_session_cache无;

语境:

流,服务器

设置存储会话参数的高速缓存的类型和大小。缓存可以是以下任何一种类型:

off严禁使用会话缓存:nginx明确告诉客户端会话可能不会被重用。none会话缓存的使用被轻轻禁止:nginx告诉客户端会话可能会被重用,但实际上并不会将会话参数存储在缓存中。builtin在OpenSSL中构建的缓存; 仅由一个工作进程使用。缓存大小在会话中指定。如果没有给出大小,则等于20480个会话。使用内置高速缓存可能导致内存碎片。shared所有工作进程之间共享的缓存。缓存大小以字节为单位指定; 一兆字节可以存储大约4000个会话。每个共享缓存都应该有一个任意名称。具有相同名称的缓存可用于多台服务器。

两种缓存类型可以同时使用,例如:

ssl_session_cache builtin:1000 shared:SSL:10m;

但只使用没有内置缓存的共享缓存应该更高效。

句法:

ssl_session_ticket_key文件;

默认:

语境:

流,服务器

file使用用于加密和解密TLS会话票据的密钥设置a 。如果必须在多个服务器之间共享相同的密钥,则该指令是必需的。默认情况下,使用随机生成的密钥。

如果指定了多个密钥,则仅使用第一个密钥来加密TLS会话票据。这允许配置密钥旋转,例如:

ssl_session_ticket_key current.key;
ssl_session_ticket_key previous.key;

file必须含有80或48个字节的随机数据,并且可以使用下面的命令创建:

openssl rand 80 > ticket.key

根据文件大小,AES256(80字节密钥,1.11.8)或AES128(48字节密钥)用于加密。

句法:

ssl_session_tickets在|上 关闭;

默认:

ssl_session_tickets on;

语境:

流,服务器

通过TLS会话票据启用或禁用会话恢复。

句法:

ssl_session_timeout时间;

默认:

ssl_session_timeout 5m;

语境:

流,服务器

指定客户端可以重新使用会话参数的时间。

句法:

ssl_trusted_certificate文件;

默认:

语境:

流,服务器

指定file带有用于验证客户端证书的PEM格式的可信CA证书。

与由ssl_client_certificate设置的证书相比,这些证书的列表不会发送给客户端。

句法:

ssl_verify_client在|上 关闭| 可选| optional_no_ca;

默认:

ssl_verify_client off;

语境:

流,服务器

启用客户端证书的验证。验证结果存储在$ ssl_client_verify变量中。如果在客户端证书验证期间发生错误或者客户端未提供所需证书,则连接将关闭。

optional参数请求客户端证书并验证它是否存在证书。

optional_no_ca参数请求客户端证书,但不要求它由可信CA证书进行签名。这适用于nginx外部的服务执行实际证书验证的情况。证书的内容可以通过$ ssl_client_cert变量访问。

句法:

ssl_verify_depth数字;

默认:

ssl_verify_depth 1;

语境:

流,服务器

设置客户端证书链中的验证深度。

嵌入式变量

ngx_stream_ssl_module模块自1.11.2开始支持变量。

$ssl_cipher返回用于建立SSL连接的密码串; $ssl_ciphers返回客户端支持的密码列表(1.11.7)。已知密码按名称列出,未知以十六进制显示,例如:

AES128-SHA:AES256-SHA:0x00ff

只有在使用OpenSSL版本1.0.2或更高版本时才支持该变量。对于旧版本,该变量仅适用于新会话,并只列出已知密码。

$ssl_client_cert以建立的SSL连接的PEM格式返回客户端证书,每行除第一行加上制表符(1.11.8); $ssl_client_fingerprint为建立的SSL连接(1.11.8)返回客户端证书的SHA1指纹; $ssl_client_i_dn根据RFC 2253(1.11.8),为建立的SSL连接返回客户端证书的“颁发者DN”字符串; $ssl_client_raw_cert以建立的SSL连接(1.11.8)的PEM格式返回客户证书; $ssl_client_s_dn根据RFC 2253(1.11.8)返回已建立的SSL连接的客户端证书的“主题DN”字符串; $ssl_client_serial为已建立的SSL连接(1.11.8)返回客户端证书的序列号;$ssl_client_v_end返回客户端证书的结束日期(1.11.8); $ssl_client_v_remain返回客户端证书过期的天数(1.11.8); $ssl_client_v_start返回客户端证书的开始日期(1.11.8); $ssl_client_verify返回客户端证书验证结果(1.11.8):如果证书不存在,则返回“ SUCCESS”,“ FAILED:reason”和“ NONE”; $ssl_curves返回客户端支持的曲线列表(1.11.7)。已知曲线按名称列出,未知以十六进制显示,例如:

0x001d:prime256v1:secp521r1:secp384r1

只有在使用OpenSSL版本1.0.2或更高版本时才支持该变量。对于旧版本,变量值将是一个空字符串。该变量仅适用于新会话。

$ssl_protocol返回建立的SSL连接的协议; $ssl_server_name通过SNI返回请求的服务器名称; $ssl_session_id返回建立的SSL连接的会话标识符; 如果SSL会话被重用,则$ssl_session_reused返回“ r”;否则返回“ ” .

ngx_stream_ssl_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