在 CentOS 6 上使用 OpenSSL 1.0.2k 编译 nginx 1.11.9

在 CentOS 6 上使用 OpenSSL 1.0.2k 编译 nginx 1.11.9

我正在运行 CentOS 6 x64,我希望根据 OpenSSL 1.0.2k 编译 nginx 1.11.9,以便我可以使用 HTTP/2。

我已将 openssl-1.0.2k 下载到 /usr/local/src:

[root@qpat1 nginx-1.11.9]# ls /usr/local/src openssl-1.0.2k

我正在尝试使用以下命令编译 nginx:

$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-openssl=/usr/local/src/openssl-1.0.2k $ make

它工作了一段时间然后启动了:

objs/src/mail/ngx_mail_pop3_module.o \ objs/src/mail/ngx_mail_pop3_handler.o \ objs/src/mail/ngx_mail_imap_module.o \ objs/src/mail/ngx_mail_imap_handler.o \ objs/src/mail/ngx_mail_smtp_module.o \ objs/src/mail/ngx_mail_smtp_handler.o \ objs/src/mail/ngx_mail_auth_http_module.o \ objs/src/mail/ngx_mail_proxy_module.o \ objs/src/stream/ngx_stream.o \ objs/src/stream/ngx_stream_variables.o \ objs/src/stream/ngx_stream_script.o \ objs/src/stream/ngx_stream_handler.o \ objs/src/stream/ngx_stream_core_module.o \ objs/src/stream/ngx_stream_log_module.o \ objs/src/stream/ngx_stream_proxy_module.o \ objs/src/stream/ngx_stream_upstream.o \ objs/src/stream/ngx_stream_upstream_round_robin.o \ objs/src/stream/ngx_stream_write_filter_module.o \ objs/src/stream/ngx_stream_ssl_module.o \ objs/src/stream/ngx_stream_realip_module.o \ objs/src/stream/ngx_stream_limit_conn_module.o \ objs/src/stream/ngx_stream_access_module.o \ objs/src/stream/ngx_stream_geo_module.o \ objs/src/stream/ngx_stream_map_module.o \ objs/src/stream/ngx_stream_split_clients_module.o \ objs/src/stream/ngx_stream_return_module.o \ objs/src/stream/ngx_stream_upstream_hash_module.o \ objs/src/stream/ngx_stream_upstream_least_conn_module.o \ objs/src/stream/ngx_stream_upstream_zone_module.o \ objs/src/stream/ngx_stream_ssl_preread_module.o \ objs/ngx_modules.o \ -Wl,-z,relro -Wl,-z,now -pie -ldl -lpthread -lpthread -lcrypt -lpcre /usr/local/src/openssl-1.0.2k/.openssl/lib/libssl.a /usr/local/src/openssl-1.0.2k/.openssl/lib/libcrypto.a -ldl -lz \ -Wl,-E /usr/bin/ld: /usr/local/src/openssl-1.0.2k/.openssl/lib/libssl.a(s23_meth.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC /usr/local/src/openssl-1.0.2k/.openssl/lib/libssl.a: could not read symbols: Bad value collect2: ld returned 1 exit status make[1]: *** [objs/nginx] Error 1 make[1]: Leaving directory `/root/nginx-http2/nginx-1.11.9' make: *** [build] Error 2

我已经尝试了所有我能想到的方法。我按照针对类似问题找到的说明使用 -fPIC 编译 OpenSSL:

./config -fPIC make depend make make install

似乎什么都没起作用。任何建议都值得感激。

答案1

在 IRC 的启发下,我发现 nginx 的 configure 脚本生成的 Makefile 无法编译 OpenSSL(或您正在使用的任何其他源,如 zlib)-fPIC。编辑生成的 Makefile(objs/Makefile),找到 openssl./config命令,然后添加-fPIC到该命令行即可进行编译。

答案2

我有关于如何从源代码构建 Nginx 的说明这个答案。这很简单。我没有构建 OpenSSL,而是使用了二进制文件。

相关内容