Nginx

在 CentOS 6 上使用 OpenSSL 1.0.2k 編譯 nginx 1.11.9

  • February 8, 2017

我正在執行 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

似乎沒有任何工作。任何建議表示讚賞。

在 IRC 的啟發下,我發現 nginx 的配置腳本生成的 Makefile 不能用-fPIC. 編輯生成的 Makefile (objs/Makefile),找到 openssl./config命令,並添加-fPIC到該命令行使其編譯。

我在這個答案上有關於如何從原始碼建構 Nginx 的說明。這很容易。我沒有建構 OpenSSL,我使用了二進製文件。

引用自:https://serverfault.com/questions/831182