NOTE

1.4 编译安装

Nginx 源码编译安装、启动、参数与目录。

Web Server / Nginx创建于 更新于 约 1 分钟读完historical

这是历史学习笔记,可能存在过时或不完整的理解。

1. 搭建步骤

1.1. 下载

mkdir src
cd src

# PCRE version 4.4 - 8.40
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.tar.gz

# zlib version 1.1.3 - 1.2.11
wget http://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz

# OpenSSL version 1.0.2 - 1.1.0
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz

# lua环境
wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz && tar xzvf LuaJIT-2.0.2.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz && tar xzvf v0.3.0.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz && tar xzvf v0.10.9rc7.tar.gz

1.2. 安装开发环境

sudo apt install build-essential -y
sudo apt-get install libxml2 libxml2-dev libxslt1-dev -y
sudo apt-get install -y libgd-dev
sudo apt-get install -y libgeoip-dev
sudo apt-get install lua5.3 -y
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

1.3. 编译安装

./configure --prefix=<USER_HOME>/software/nginx/nginx \
            --sbin-path=<USER_HOME>/software/nginx/nginx/sbin/nginx \
            --modules-path=<USER_HOME>/software/nginx/nginx/modules \
            --conf-path=<USER_HOME>/software/nginx/nginx/conf/nginx.conf \
            --error-log-path=<USER_HOME>/software/nginx/nginx/log/error.log \
            --pid-path=<USER_HOME>/software/nginx/nginx/log/nginx.pid \
            --lock-path=<USER_HOME>/software/nginx/nginx/log/nginx.lock \
            --user=<USER> \
            --group=wheel \
            --with-select_module \
            --with-poll_module \
            --with-threads \
            --with-file-aio \
            --with-http_ssl_module \
            --with-http_v2_module \
            --with-http_realip_module \
            --with-http_addition_module \
            --with-http_xslt_module=dynamic \
            --with-http_image_filter_module=dynamic \
            --with-http_geoip_module=dynamic \
            --with-http_sub_module \
            --with-http_dav_module \
            --with-http_flv_module \
            --with-http_mp4_module \
            --with-http_gunzip_module \
            --with-http_gzip_static_module \
            --with-http_auth_request_module \
            --with-http_random_index_module \
            --with-http_secure_link_module \
            --with-http_degradation_module \
            --with-http_slice_module \
            --with-http_stub_status_module \
            --http-log-path=<USER_HOME>/software/nginx/nginx/log/access.log \
            --http-client-body-temp-path=<USER_HOME>/software/nginx/nginx/temp/client_temp \
            --http-proxy-temp-path=<USER_HOME>/software/nginx/nginx/temp/proxy_temp \
            --http-fastcgi-temp-path=<USER_HOME>/software/nginx/nginx/temp/fastcgi_temp \
            --http-uwsgi-temp-path=<USER_HOME>/software/nginx/nginx/temp/uwsgi_temp \
            --http-scgi-temp-path=<USER_HOME>/software/nginx/nginx/temp/scgi_temp \
            --with-mail=dynamic \
            --with-mail_ssl_module \
            --with-stream=dynamic \
            --with-stream_ssl_module \
            --with-stream_realip_module \
            --with-stream_geoip_module=dynamic \
            --with-stream_ssl_preread_module \
            --with-compat \
            --with-pcre=<USER_HOME>/software/nginx/src/pcre-8.40 \
            --with-pcre-jit \
            --with-zlib=<USER_HOME>/software/nginx/src/zlib-1.2.11  \
            --with-openssl=<USER_HOME>/software/nginx/src/openssl-OpenSSL_1_0_2u \
            --with-openssl-opt=no-nextprotoneg \
            --add-module=<USER_HOME>/software/nginx/src/ngx_devel_kit-0.3.0 \
            --add-module=<USER_HOME>/software/nginx/src/lua-nginx-module-0.10.9rc7 \
            --with-debug

make -j2 && make install

1.4. 启动

sudo nginx -c conf/nginx.conf

2. 查看安装时所选用的参数

nginx -V

3. 目录介绍

4. 参考

讨论

使用 GitHub 账号参与讨论,评论会保存在 GitHub Issues 中。在 GitHub 查看