当前位置:首页 > 开发 > 互联网 > 正文

Nginx源码构建、编译并安装

发表于: 2015-05-27   作者:bert82503   来源:转载   浏览次数:
摘要: 本文主要记录自己在“从Nginx源码构建、编译并安装 ”过程中遇到的一些问题及详细步骤,通过以下方式构建的Nginx集成了 SSL、 Lua、 Nginx Upstream Health Check、解压缩 功能。   # 1. 下载安装包( http://nginx.org/en/download.html) wget  http://nginx.org/
本文主要记录自己在“从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

 

Nginx源码构建、编译并安装

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
基本步骤: 1.首先停止现有web系统, #/etc/init.d/apache2 stop 2.将源码拷贝到/usr/local/src #cp
安装环境: 操作系统:Ubuntu 12.04 Nginx: V1.4.2 PCRE: V8.33 zlib: V1.2.8 下载上述源包到当
1:首先安装Nginx所需要的库 a.GCC编译器 yum install -y gcc b.G++编译器:C++来编译Nginx的http模
目录环境:win7+vs2010,以版本192为例 第一步:源码下载:http://download.osgeo.org/gdal/gdal192
Linux(6.4)+Nginx(1.4.1)+Mysql(5.6.12)+Php(5.5.0)源码编译安装 环境介绍 内核2.6.32,系统为CentO
1:以CentOS-6.4安装的基础上进行编译安装nginx: 第一步检查安装gcc gcc-v #检查gcc编译器 yum -y
公司空出来一些服务器,很久没有来练手了,于是便开始有了这篇博客,记录下过程。 Nginx 这个不多说
本文主要简单介绍Nginx特点及在centos 6.6 x86_64系统环境下编译安装轻量级http服务器nginx的方法
Think in Java源码编译与安装 1:将你的下载的源码解压到c:\TIJ4\code目录中 2:安装JDK se5 最好是 j
Nginx 可以承受 3 万并发连接数,Apache 默认最大连接数是 256 个。 编译安装 ① 下载 在 Nginx 的
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号