在 nginx.conf 中添加 SSL 相关信息后报错

2016-11-09 17:54:56 +08:00
 admol
server {
        listen 443 ssl;
        server_name  www.xxxx.net;
         ssl_certificate /etc/letsencrypt/live/www.xxxx.net/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/www.xxxx.net/privkey.pem;
        ssl_ciphers "xxxxxxxx";
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_stapling on;
        ssl_stapling_verify on;
}

使用的命令./nginx -t 检测的时候老是在 ssl 部分报错,去掉 ssl 就可以通过

是因为 nginx 缺少 ssl 模块吗?

但是我有执行过命令 ./configure --with-http_stub_status_module --with-http_ssl_module --with-openssl=/usr/bin/openssl

请问是姿势没对吗....

15793 次点击
所在节点    SSL
17 条回复
lhbc
2016-11-09 17:58:55 +08:00
你打了这么多字,都舍不得把 nginx -t 的结果贴出来……
admol
2016-11-09 18:03:39 +08:00
@lhbc nginx -t 说的也就是第多少行有错误,所以我就没复制出来了.....
listen 443 ssl; 行有错误, 去掉 ssl ,该行可以通过,然后就是下面的 ssl_certificate 每行都通不过...
admol
2016-11-09 18:07:34 +08:00
@lhbc
nginx -t 输出信息
nginx: [emerg] unknown directive "ssl_certificate" in /usr/local/nginx/conf/nginx.conf:39
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

error.log 日志信息仅仅就第一句...
lhbc
2016-11-09 18:13:26 +08:00
nginx -V
ldd nginx

估计你没有把 OpenSSL 编译进去
1. 你可以不加--with-openssl 参数编译,这样使用系统的 OpenSSL 库
2. 加--with-openssl 的话,后面应该是 OpenSSL 的源码,不是 OpenSSL 的安装目录
3. 如果你要调用自编译的 OpenSSL 的库,那你得指定 LD_LIBRARY_PATH 等变量,并且加--with-ld-opt
--with-cc-opt 这些参数
admol
2016-11-09 18:27:01 +08:00
@lhbc
nginx -V
nginx version: nginx/1.11.2

ldd nginx
linux-vdso.so.1 => (0x00007fff62994000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f1e890b4000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f1e88e97000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f1e88c5f000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x00007f1e88a32000)
libz.so.1 => /lib64/libz.so.1 (0x00007f1e8881c000)
libc.so.6 => /lib64/libc.so.6 (0x00007f1e88487000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1e892c1000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f1e8820e000)

然后按照你说的去掉--with-openssl 进行编译,但是出现错误:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

但是按照网上说的运行
yum -y install openssl openssl-devel
结果又说 Nothing to do
ooxxcc
2016-11-09 18:29:05 +08:00
好好的,为什么不用系统自带的 nginx

自己编译的话仔细看 configure 的输出,估计会有提示
ooxxcc
2016-11-09 18:30:19 +08:00
在你贴的前面几行估计会有试图寻找 openssl 然后没找到之类的输出,你每次都把最重要的 log 给截掉了……

干脆直接去官网下份新的 openssl 然后用--with-openssl=选项好了
admol
2016-11-09 18:34:29 +08:00
@ooxxcc
仅运行 ./configure 部分提示
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
说明确实没用到吧

其实我今天就是把 openssl 从 1.0.1 升级到了 1.1.0,是不是直接把--with-openssl= 这个参数直接指定给我的最新安装目录就行了呢? 我现在是这个版本 https://www.openssl.org/source/openssl-1.1.0b.tar.gz
admol
2016-11-09 18:37:21 +08:00
我刚刚尝试加上了--with-openssl 这个参数,然后从新编译,出现结果:

Configuration summary
+ using system PCRE library
+ using OpenSSL library: /root/openssl-1.1.0b
+ using system zlib library
ooxxcc
2016-11-09 18:37:34 +08:00
@admol 不要每次把输出过滤一部分再贴出来,在一个帖子里你已经第三次这么做了。太长就用 pastebin 之类的工具,以免漏掉信息。

是的,不是安装目录,是源代码目录
ooxxcc
2016-11-09 18:37:58 +08:00
@admol 这样大概是 ok 的,试试吧
admol
2016-12-15 18:06:22 +08:00
@lhbc @ooxxcc
请问下大神, 我现在想添加一个模块[ngx_http_proxy_module]( http://nginx.org/en/docs/http/ngx_http_proxy_module.html) ,
``./configure --prefix=/usr/local/nginx --with-http_proxy_module --with-http_stub_status_module --with-http_ssl_module --with-openssl=/root/openssl-1.1.0b``

结果报错:
./configure: error: invalid option "--with-http_proxy_module"
请问下要添加 ngx_http_proxy_module 这个模块 参数怎么写呢?
lhbc
2016-12-15 18:32:01 +08:00
@admol 这个模块是默认编译进去的,没有这个参数
要禁止用 --without-http_proxy_module
admol
2016-12-16 14:19:41 +08:00
@lhbc 原来如此 感谢...
admol
2016-12-16 16:47:54 +08:00
@lhbc 你好, 请问下我在我的 nginx.conf 中添加了最后三个 proxy_set_header 后, 访问就 404 了 , 添加这个的目的是为了后端的服务拿到真实的访问 IP , 去掉就可以正常的访问 , 能否帮忙看看怎么回事呢 ?谢谢

配置详细见:http://pastebin.com/5jKJ9fdz
lhbc
2016-12-16 17:18:15 +08:00
源站没绑域名吧。
admol
2016-12-16 17:32:53 +08:00
@lhbc 什么意思? 能说详细点吗 ? 不是很懂什么源站 ? 我配置最后那三个 proxy_set_header 前面的# 去掉网站就不能正常访问, 现在加上了是可以正常访问的 .....

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/319353

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX