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


Linux 编译安装 OpenResty

OpenResty Linux 大约 2522 字

下载 OpenResty

本文以openresty-1.19.3.1为例。

wget https://openresty.org/download/openresty-1.19.3.1.tar.gz
tar -zxvf openresty-1.19.3.1.tar.gz

可能出现的错误

缺少OpenSSLpcrezlib依赖

下载依赖,无需安装,只需在./configure阶段指定--with-pcre--with-openssl目录文件夹即可。

建议下载到/usr/local/openresty/lib下。

openssl 1.1.1ihttps://www.openssl.org/source

/usr/local/openresty/lib/openssl-1.1.1i/test文件夹有1.4G空间占用,可删除。

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar -zxvf openssl-1.1.1i.tar.gz

pcre 8.44https://ftp.pcre.org/pub/pcre

wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -zxvf pcre-8.44.tar.gz

zlib 1.2.11http://www.zlib.net

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz

缺少C++编译器

configure: error: You need a C++ compiler for C++ support.

安装gccgcc-c++

yum install -y gcc gcc-c++

扩展

去除Nginx源码中硬编码的错误页面版本号。

源码路径

ngx_http_special_response.c文件的222936行,可在vim中使用:nn为行数)跳转至如下代码,或搜索NGINX_VER关键词。

NGINX_VERNGINX_VER_BUILDopenresty替换为自己想要的字符串,或者删除也可以。

openresty-1.19.3.1/bundle/nginx-1.19.3/src/http/ngx_http_special_response.c

去除版本信息

修改前代码如下:

static u_char ngx_http_error_full_tail[] =
"<hr><center>" NGINX_VER "</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_build_tail[] =
"<hr><center>" NGINX_VER_BUILD "</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_tail[] =
"<hr><center>openresty</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

去除版本信息后代码:

static u_char ngx_http_error_full_tail[] =
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_build_tail[] =
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_tail[] =
"</body>" CRLF
"</html>" CRLF
;

编译安装

openresty-1.19.3.1文件夹根目录执行。

-j8:指定8CPU工作,可根据服务器CPU核数调整。

--prefix:指定安装目录,默认/usr/local/openresty

./configure -j8 --prefix=/usr/local/openresty --with-http_v2_module --with-http_stub_status_module --with-http_ssl_module --with-stream --with-openssl=/usr/local/openresty/lib/openssl-1.1.1i/  --with-pcre=/usr/local/openresty/lib/pcre-8.44/ --with-zlib=/usr/local/openresty/lib/zlib-1.2.11/

编译

make -j8

安装

make install

建立软链

/usr/local/sbin下建立nginx命令,链接到真实命令/usr/local/openresty/nginx/sbin/nginx

ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/sbin/nginx

备注

虽然编译安装时指定的--prefix/usr/local/openresty,但nginx真实的--prefix/usr/local/openresty/nginx,可使用nginx -V查看。

下载地址

http://openresty.org/en/download.html

参考

http://openresty.org/en/installation.html

阅读 3077 · 发布于 2021-05-04

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

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

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