在Nginx服务器中怎么使用LibreSSL

本篇内容介绍了“在Nginx服务器中怎么使用LibreSSL”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

安装

直接从源码编译libressl,构建过程的输出非常简洁,源码还附带测试用例及提供并行构建支持(见附录)。

# 用于构建及安装 libressl 的选项 
 
$ ./configure --prefix=/usr ldflags=-lrt && make check && sudo make install

新安装的 libressl 可替代openssl以相同的方式运行,但要注意:正如 sabotage-linux 的 spencerjohn 和 gentoo 的 hanno böck 所说的那样,用libressl完全替代操作系统中的openssl会很麻烦。[3,4]

libressl 会报告其版本为 libressl 2.0, openssl命令的使用方法与openssl一样:

复制代码 代码如下:

$ which openssl
/usr/bin/openssl
 
$ openssl version
libressl 2.0
 
$ openssl s_client -host www.openssl.org -port 443
connected(00000003)
depth=2 c = be, o = globalsign nv-sa, ou = root ca, cn = globalsign root ca
verify error:num=19:self signed certificate in certificate chain
verify return:0
---
certificate chain
 0 s:/c=gb/ou=domain control validated/cn=*.openssl.org
   i:/c=be/o=globalsign nv-sa/cn=globalsign domain validation ca - g2
 1 s:/c=be/o=globalsign nv-sa/ou=root ca/cn=globalsign root ca
   i:/c=be/o=globalsign nv-sa/ou=root ca/cn=globalsign root ca
 2 s:/c=be/o=globalsign nv-sa/cn=globalsign domain validation ca - g2
   i:/c=be/o=globalsign nv-sa/ou=root ca/cn=globalsign root ca
---
server certificate
-----begin certificate-----
... skip
-----end certificate-----
subject=/c=gb/ou=domain control validated/cn=*.openssl.org
issuer=/c=be/o=globalsign nv-sa/cn=globalsign domain validation ca - g2
---
no client certificate ca names sent
---
ssl handshake has read 4136 bytes and written 707 bytes
---
new, tlsv1/sslv3, cipher is dhe-rsa-aes256-gcm-sha384
server public key is 2048 bit
secure renegotiation is supported
compression: none
expansion: none
ssl-session:
    protocol  : tlsv1.2
    cipher    : dhe-rsa-aes256-gcm-sha384
    tls session ticket lifetime hint: 300 (seconds)
    tls session ticket:

确认了 libressl 能够使用后,我便动手让 nginx 来使用 libressl 。尽管在仍然使用 openssl 0.9.x 的旧系统中,通常我都会静态构建 nginx+openssl 以使最新和最好的 tls 版本可用。第一次尝试,只使用 ./configure --with-openssl=/path/to/libressl 就大错特错了,因为 nginx 已经完全与 openssl 的构建过程融合了:

  •     可使用名为./config的脚本来替代./configure(容易解决)

  •     openssl 会收集在 .openssl/lib 下的 objects(.obj) 文件和其他文件来链接进二进制文件和库文件,而 libressl 将这些文件分开存放在 crypto/.libs 和 ssl/.libs。


尝试通过手工建立目录层次(.openssl/lib)及根据 libressl 成功构建后出现的错误提示(见下面的错误信息)来复制文件以解决这些问题;在编译 libressl 时,我看到一个类似可以通过使用 ldflags=-lrt 选项来解决问题的错误提示,但在尝试编译nginx并链接到已静态编译过的libressl库时仍然无法修复这个问题(但我依然继续):
 

复制代码 代码如下:

  ...
 
  objs/addon/nginx-upstream-fair/ngx_http_upstream_fair_module.o \
  objs/addon/src/ngx_http_headers_more_filter_module.o \
  objs/addon/src/ngx_http_headers_more_headers_out.o \
  objs/addon/src/ngx_http_headers_more_headers_in.o \
  objs/addon/src/ngx_http_headers_more_util.o \
  objs/addon/src/ngx_http_encrypted_session_module.o \
  objs/addon/src/ngx_http_encrypted_session_cipher.o \
  objs/ngx_modules.o \
  -wl,-e -lpthread -lcrypt -l/usr/lib -lm -llua5.1 -lpcre /data/builds/froggstack/nginx_modules/openssl/.openssl/lib/libssl.a /data/builds/froggstack/nginx_modules/openssl/.openssl/lib/libcrypto.a -ldl -lz
/data/builds/froggstack/nginx_modules/openssl/.openssl/lib/libcrypto.a(libcompat_la-getentropy_linux.o): in function `getentropy_fallback':
/data/builds/froggstack/nginx_modules/openssl/crypto/compat/getentropy_linux.c:324: undefined reference to `clock_gettime'
/data/builds/froggstack/nginx_modules/openssl/crypto/compat/getentropy_linux.c:395: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/nginx] error 1
make[1]: leaving directory `/data/builds/froggstack/src_nginx/nginx-1.6.0'
make: *** [build] error 2

下一个尝试是在安装了 libressl 的前提下通过链接到 libressl 的动态库来构建 nginx,最终成功了(完整的nginx ./configure 选项参数见附录)。 运行 nginx-libressl -t 测试成功,并将 /usr/bin/nginx 替换成新的二进制可执行文件和运行 /etc/init.d/nginx restart,更新后的 nginx + libressl 上线了。任何配置文件和 nginx 的 ssl 配置都不需要修改,非常好!

测试

在各种 linux 和 android 的浏览器上测试都没有发现问题;甚至在一台已被遗忘的装有2007年10月发布并已过时的附带 openssl 0.9.8g 19 的 debian 5 上使用像 w3m 这样的控制台浏览器上浏览也没有问题。

在 ssllabs.com 上测试的得分为 a+,成绩与之前的配置一样;在使用了 libressl 后,唯一给出的提示是加密算法 chacha20-poly1305 还处于实验阶段。

在Nginx服务器中怎么使用LibreSSL  nginx 第1张

在Nginx服务器中怎么使用LibreSSL  nginx 第2张

做了一个小小的性能测试,结果显示没有什么大问题;libressl 与平均水平相比慢了 4%。原因可能是 openssl 是静态链接到 nginx 的,而 libressl 则是动态链接到 nginx 的,所以会产生更多的资源开销。

在Nginx服务器中怎么使用LibreSSL  nginx 第3张

纯数字的测试结果:

复制代码 代码如下:


| parallel requests | openssl-rps | libressl-rps
| 10                | 2341.75     | 2260.5
| 20                | 2459.75     | 2418.25
| 30                | 2472        | 2397
| 40                | 2485        | 2384.5
| 50                | 2445        | 2382.25
| 60                | 2453.25     | 2390.75
| 70                | 2426.25     | 2347.25
| 80                | 2346.5      | 2227.5
| 90                | 2325.5      | 2211
| 100               | 2297.75     | 2318.25

性能测试方式的一些说明可能在附录中找到。

“在Nginx服务器中怎么使用LibreSSL”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注蜗牛博客网站,小编将为大家输出更多高质量的实用文章!

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接