Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Linux 编译安装 Nginx

Nginx Linux OpenSSL 大约 2341 字

下载解压

wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1

查看模块支持

./configure --help

安装配置

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream

缺少 pcre、OpenSSL 依赖

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

下载依赖

无需安装。

pcre

wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.43/pcre-8.43.tar.gz
tar -zxvf pcre-8.43.tar.gz

OpenSSL

wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz
tar -zxvf openssl-1.1.0h.tar.gz

编译出错

cd /usr/local/pcre/bin \
    && if [ -f Makefile ]; then make distclean; fi \
    && CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
    ./configure --disable-shared 
/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/local/pcre/bin/Makefile] Error 127
make[1]: Leaving directory `/home/root/nginx-1.16.1'
make: *** [build] Error 2

cd /usr/local/openssl/bin/ \
    && if [ -f Makefile ]; then make clean; fi \
    && ./config --prefix=/usr/local/openssl/bin//.openssl no-shared no-threads  \
    && make \
    && make install_sw LIBDIR=lib
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/openssl/bin//.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/home/root/nginx-1.16.1'
make: *** [build] Error 2

指定依赖路径

--with-pcre--with-openssl指定到依赖的根目录即可,无需指定到bin目录。

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-pcre=/home/root/pcre-8.40/ --with-openssl=/home/root/openssl-1.1.0h/

编译

先不一起执行make install,编译成功后,进入objs/目录下,执行./nginx -t./nginx -V检查

make

安装

make install

运行

指定了--prefix,安装好后到/usr/local/nginx/sbin下运行即可。

./nginx

官网

Nginx:http://nginx.org

pcre:http://www.pcre.org

OpenSSL:https://www.openssl.org

阅读 4320 · 发布于 2019-04-19

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批