Nginx源码构建、编译并安装

本文主要记录自己在“从Nginx源码构建、编译并安装 ”过程中遇到的一些问题及详细步骤,通过以下方式构建的Nginx集成了 SSL、LuaNginx Upstream Health Check、解压缩 功能。
 
# 1. 下载安装包http://nginx.org/en/download.html
wget  https://github.com/openresty/lua-upstream-nginx-module/archive/v0.02.tar.gz  -O lua-upstream-nginx-module-0.02.tar.gz
 
 
# 2. 解压缩安装包,并创建“软链接”
tar -xzvf  nginx-1.7.10.tar.gz
tar -xzvf  pcre- 8.36.tar.gz
mv pcre-8.36 nginx-1.7.10
tar -xzvf  openssl-1.0.2a.tar.gz
mv openssl-1.0.2a nginx-1.7.10
tar -xzvf  zlib-1.2.8.tar.gz
mv zlib-1.2.8 nginx-1.7.10
tar -xzvf  ngx_devel_kit-0.2.19.tar.gz
mv ngx_devel_kit-0.2.19 nginx-1.7.10
tar -xzvf  lua-nginx-module-0.9.15.tar.gz
mv lua-nginx-module-0.9.15  nginx-1.7.10
tar -xzvf  lua-upstream-nginx-module-0.02.tar.gz
mv lua-upstream-nginx-module-0.02  nginx-1.7.10
mv nginx-1.7.10 /usr/apps/nginx-1.7.10
cd  /usr/apps
ln -s  nginx-1.7.10  nginx
cd  nginx
 
 
# 3. 修改Nginx的openssl编译配置信息并编译OpenSSL
# 3.1 修改  nginx/auto/lib/openssl/conf
# CORE_INCS="$CORE_INCS $OPENSSL/ .openssl/include"
# CORE_DEPS="$CORE_DEPS $OPENSSL/ .openssl/include/openssl/ssl.h"
# CORE_LIBS="$CORE_LIBS $OPENSSL/ .openssl/lib/libssl.a"
# CORE_LIBS="$CORE_LIBS $OPENSSL/ .openssl/lib/libcrypto.a"

CORE_INCS="$CORE_INCS $OPENSSL/ include"
CORE_DEPS="$CORE_DEPS $OPENSSL/ include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/ libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/ libcrypto.a"
 
# 3.2 编译并构建 OpenSSL
cd openssl-1.0.2a/
./config
make
cd ..
 
【问题】
1. make[1]: *** [/apps/lib/openssl-1.0.2a/.openssl/include/openssl/ssl.h] Error 2
2. cc: error: openssl-1.0.2a/ libssl.a: 未找到相关文件或目录、 cc: error: openssl-1.0.2a/libcrypto.a: 未找到相关文件或目录
原因是没有先对OpenSSL进行编译构建,需要先构建生成这两个包。
 

# 4. build(构建)
./configure --prefix=/usr/apps/ nginx \
--with-ld-opt="-Wl,-rpath,$LUAJIT_LIB" \
--with-http_ssl_module \
--with-pcre=pcre- 8.36 \
--with-openssl=openssl-1.0.2a \
--with-zlib=zlib-1.2.8 \
--add-module=ngx_devel_kit-0.2.19 \
--add-module=lua-nginx-module-0.9.15 \
--add-module=lua-upstream-nginx-module-0.02
 
====  构建日志  ====
checking for OS
+ Linux 3.13.0-24-generic x86_64
checking for  C compiler ... found
+ using  GNU C compiler
gcc version: 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 
...
configuring additional modules
adding module in  ngx_devel_kit-0.2.19
ngx_devel_kit was configured
adding module in  lua-nginx-module-0.9.15
checking for LuaJIT library in /usr/apps/luajit/lib and /usr/apps/luajit/include/luajit-2.0 ( specified by the LUAJIT_LIB and LUAJIT_INC env) ... found
checking for export symbols by default (-E) ... found
checking for export symbols by default (--export-all-symbols) ... not found
checking for SO_PASSCRED ... found
ngx_http_lua_module was configured
adding module in  lua-upstream-nginx-module-0.02
ngx_http_lua_upstream_module was configured
creating objs/Makefile

Configuration summary (配置摘要)
+ using PCRE library: pcre-8.36
+ using OpenSSL library: openssl-1.0. 2a
md5: using  OpenSSL library
sha1: using OpenSSL library
+ using zlib library: zlib-1.2.8

nginx path prefix: "/usr/apps/ nginx"
nginx  binary file: "/usr/apps/nginx/ sbin/nginx"
nginx configuration prefix: "/usr/apps/nginx/conf"
nginx  configuration file: "/usr/apps/nginx/ conf/nginx.conf"
nginx  pid file: "/usr/apps/nginx/ logs/nginx.pid"
nginx  error log file: "/usr/apps/nginx/ logs/error.log"
nginx  http access log file: "/usr/apps/nginx/ logs/access.log"
nginx  http client request body temporary files: "client_body_temp"
nginx  http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
 
 
# 5. make(编译)
make -j2

==== 编译日志  ====
...
cc -o objs/nginx \
objs/src/core/nginx.o \
objs/src/core/ngx_ log.o \
objs/src/core/ngx_palloc.o \
objs/src/core/ngx_array.o \
objs/src/core/ngx_list.o \
objs/src/core/ngx_hash.o \
objs/src/core/ngx_buf.o \
objs/src/core/ngx_queue.o \
objs/src/core/ngx_ output_chain.o \
objs/src/core/ngx_string.o \
objs/src/core/ngx_parse.o \
objs/src/core/ngx_inet.o \
objs/src/core/ngx_file.o \
objs/src/core/ngx_crc32.o \
objs/src/core/ngx_murmurhash.o \
objs/src/core/ngx_md5.o \
objs/src/core/ngx_rbtree.o \
objs/src/core/ngx_radix_tree.o \
objs/src/core/ngx_slab.o \
objs/src/core/ngx_times.o \
objs/src/core/ngx_shmtx.o \
objs/src/core/ngx_ connection.o \
objs/src/core/ngx_cycle.o \
objs/src/core/ngx_spinlock.o \
objs/src/core/ngx_cpuinfo.o \
objs/src/core/ngx_conf_file.o \
objs/src/core/ngx_resolver.o \
objs/src/core/ngx_open_file_cache.o \
objs/src/core/ngx_crypt.o \
objs/src/core/ngx_proxy_protocol.o \
objs/src/core/ngx_syslog.o \
objs/src/event/ngx_ event.o \
objs/src/event/ngx_event_timer.o \
objs/src/event/ngx_event_posted.o \
objs/src/event/ngx_event_busy_lock.o \
objs/src/event/ngx_ event_accept.o \
objs/src/event/ngx_ event_connect.o \
objs/src/event/ngx_ event_pipe.o \
objs/src/os/unix/ngx_ time.o \
objs/src/os/unix/ngx_errno.o \
objs/src/os/unix/ngx_alloc.o \
objs/src/os/unix/ngx_files.o \
objs/src/os/unix/ngx_ socket.o \
objs/src/os/unix/ngx_ recv.o \
objs/src/os/unix/ngx_ readv_chain.o \
objs/src/os/unix/ngx_udp_recv.o \
objs/src/os/unix/ngx_ send.o \
objs/src/os/unix/ngx_ writev_chain.o \
objs/src/os/unix/ngx_ channel.o \
objs/src/os/unix/ngx_shmem.o \
objs/src/os/unix/ngx_ process.o \
objs/src/os/unix/ngx_daemon.o \
objs/src/os/unix/ngx_setaffinity.o \
objs/src/os/unix/ngx_setproctitle.o \
objs/src/os/unix/ngx_ posix_init.o \
objs/src/os/unix/ngx_user.o \
objs/src/os/unix/ngx_ process_cycle.o \
objs/src/os/unix/ngx_linux_init.o \
objs/src/event/modules/ngx_ epoll_module.o \
objs/src/os/unix/ngx_linux_sendfile_chain.o \
objs/src/core/ngx_regex.o \
objs/src/http/ngx_ http.o \
objs/src/http/ngx_ http_core_module.o \
objs/src/http/ngx_http_special_response.o \
objs/src/http/ngx_ http_request.o \
objs/src/http/ngx_http_parse.o \
objs/src/http/ngx_http_header_filter_module.o \
objs/src/http/ngx_http_write_filter_module.o \
objs/src/http/ngx_http_copy_filter_module.o \
objs/src/http/modules/ngx_ http_log_module.o \
objs/src/http/ngx_ http_request_body.o \
objs/src/http/ngx_http_variables.o \
objs/src/http/ngx_http_script.o \
objs/src/http/ngx_ http_upstream.o \
objs/src/http/ngx_ http_upstream_round_robin.o \
objs/src/http/ngx_http_parse_time.o \
objs/src/http/modules/ngx_http_static_module.o \
objs/src/http/modules/ngx_http_index_module.o \
objs/src/http/modules/ngx_http_chunked_filter_module.o \
objs/src/http/modules/ngx_http_range_filter_module.o \
objs/src/http/modules/ngx_http_headers_filter_module.o \
objs/src/http/modules/ngx_http_not_modified_filter_module.o \
objs/src/http/ngx_http_busy_lock.o \
objs/src/http/ngx_http_file_cache.o \
objs/src/http/modules/ngx_http_gzip_filter_module.o \
objs/src/http/ngx_http_postpone_filter_module.o \
objs/src/http/modules/ngx_http_ssi_filter_module.o \
objs/src/http/modules/ngx_http_charset_filter_module.o \
objs/src/http/modules/ngx_http_userid_filter_module.o \
objs/src/http/modules/ngx_http_autoindex_module.o \
objs/src/http/modules/ngx_http_auth_basic_module.o \
objs/src/http/modules/ngx_ http_access_module.o \
objs/src/http/modules/ngx_http_limit_conn_module.o \
objs/src/http/modules/ngx_ http_limit_req_module.o \
objs/src/http/modules/ngx_http_geo_module.o \
objs/src/http/modules/ngx_http_map_module.o \
objs/src/http/modules/ngx_http_split_clients_module.o \
objs/src/http/modules/ngx_http_referer_module.o \
objs/src/http/modules/ngx_ http_rewrite_module.o \
objs/src/http/modules/ngx_ http_proxy_module.o \
objs/src/http/modules/ngx_http_fastcgi_module.o \
objs/src/http/modules/ngx_http_uwsgi_module.o \
objs/src/http/modules/ngx_http_scgi_module.o \
objs/src/http/modules/ngx_http_memcached_module.o \
objs/src/http/modules/ngx_http_empty_gif_module.o \
objs/src/http/modules/ngx_http_browser_module.o \
objs/src/http/modules/ngx_ http_upstream_hash_module.o \
objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
objs/src/http/modules/ngx_ http_upstream_least_conn_module.o \
objs/src/http/modules/ngx_ http_upstream_keepalive_module.o \
objs/addon/src/ndk.o \
objs/addon/src/ngx_http_ lua_script.o \
objs/addon/src/ngx_http_lua_log.o \
objs/addon/src/ngx_http_lua_subrequest.o \
objs/addon/src/ngx_http_lua_ndk.o \
objs/addon/src/ngx_http_lua_control.o \
objs/addon/src/ngx_http_lua_ time.o \
objs/addon/src/ngx_http_lua_misc.o \
objs/addon/src/ngx_http_lua_variable.o \
objs/addon/src/ngx_http_lua_string.o \
objs/addon/src/ngx_http_lua_output.o \
objs/addon/src/ngx_http_lua_headers.o \
objs/addon/src/ngx_http_lua_req_body.o \
objs/addon/src/ngx_http_lua_uri.o \
objs/addon/src/ngx_http_lua_ args.o \
objs/addon/src/ngx_http_lua_ctx.o \
objs/addon/src/ngx_http_lua_regex.o \
objs/addon/src/ngx_http_lua_module.o \
objs/addon/src/ngx_http_lua_headers_out.o \
objs/addon/src/ngx_http_lua_headers_in.o \
objs/addon/src/ngx_http_lua_directive.o \
objs/addon/src/ngx_http_lua_consts.o \
objs/addon/src/ngx_http_lua_exception.o \
objs/addon/src/ngx_http_lua_util.o \
objs/addon/src/ngx_http_lua_cache.o \
objs/addon/src/ngx_http_ lua_contentby.o \
objs/addon/src/ngx_http_ lua_rewriteby.o \
objs/addon/src/ngx_http_ lua_accessby.o \
objs/addon/src/ngx_http_ lua_setby.o \
objs/addon/src/ngx_http_lua_capturefilter.o \
objs/addon/src/ngx_http_lua_clfactory.o \
objs/addon/src/ngx_http_lua_pcrefix.o \
objs/addon/src/ngx_http_lua_headerfilterby.o \
objs/addon/src/ngx_http_lua_shdict.o \
objs/addon/src/ngx_http_ lua_socket_tcp.o \
objs/addon/src/ngx_http_lua_api.o \
objs/addon/src/ngx_http_lua_logby.o \
objs/addon/src/ngx_http_lua_sleep.o \
objs/addon/src/ngx_http_lua_coroutine.o \
objs/addon/src/ngx_http_lua_bodyfilterby.o \
objs/addon/src/ngx_http_ lua_initby.o \
objs/addon/src/ngx_http_ lua_initworkerby.o \
objs/addon/src/ngx_http_lua_socket_udp.o \
objs/addon/src/ngx_http_lua_req_method.o \
objs/addon/src/ngx_http_lua_phase.o \
objs/addon/src/ngx_http_ lua_uthread.o \
objs/addon/src/ngx_http_lua_timer.o \
objs/addon/src/ngx_http_lua_config.o \
objs/addon/src/ngx_http_lua_worker.o \
objs/ngx_modules.o \
-Wl,-rpath,/usr/apps/luajit/lib -Wl,-E -lpthread -lcrypt -L/usr/apps/luajit/lib -lluajit-5.1 -lm pcre-8.36/.libs/libpcre.a zlib-1.2.8/libz.a
make[1]:正在离开目录 `/usr/apps/nginx-1.7.10'
make -f objs/Makefile manpage
make[1]: 正在进入目录 `/usr/apps/nginx-1.7.10'
sed -e "s|%%PREFIX%%|/usr/apps/nginx|" \
-e "s|%% PID_PATH%%|/usr/apps/nginx/ logs/nginx.pid|" \
-e "s|%% CONF_PATH%%|/usr/apps/nginx/ conf/nginx.conf|" \
-e "s|%% ERROR_LOG_PATH%%|/usr/apps/nginx/ logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]:正在离开目录 `/usr/apps/nginx-1.7.10'
 
 
# 6. install(安装)
make install

 

猜你喜欢

转载自bert82503.iteye.com/blog/2214904