前言
服务器内部署了很多容器业务,但是许多业务都是需要用80端口对外发布的,会端口占用无法正常运行。 所以决定使用nginx去反向代理对应服务,这样,就可以用80端口发布多个业务。业务容器映射至不同端口上,实现业务需求
为什么选择tengine
tengine是淘宝团队基于nginx二次开发的web服务器项目,针对大访问量网站的需求,添加了很多高级功能和特性
tengine具备什么特性
上手安装tengine
服务器系统版本 | 内核版本 | 服务器厂商 |
---|---|---|
Ubuntu21.10 | 5.13.0-28-generic | 腾讯云轻量服务器 |
tar xf tengine-2.3.3.tar.gz
tar xf pcre-8.37.tar.gz
cd pcre-8.37
./configure
# 报错缺少 C 编译环境
apt update
apt install g++ -y
# 重新编译
./configure
make && make install
cd ~
cd tengine-2.3.3/
./configure --prefix=/usr/local/tengine \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/tengine/modules \
--conf-path=/usr/local/tengine/conf/nginx.conf \
--error-log-path=/var/log/tengine/error.log \
--http-log-path=/var/log/tengine/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=root \
--group=root \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--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_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-compat \
--with-http_v2_module \
--add-module=modules/ngx_http_upstream_check_module \
--add-module=modules/ngx_http_upstream_session_sticky_module \
--with-openssl=/usr/local/openssl
# 报错找不到openssl环境,编译一下openssl
wget https://mirrors.cloud.tencent.com/openssl/source/openssl-1.1.1m.tar.gz
tar xf openssl-1.1.1m.tar.gz
cd openssl-1.1.1m/
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl no-ssl2
make && make install
cat << eof >> /etc/profile.d/openssl.sh
export PATH=/usr/local/openssl/bin:\$PATH
export LD_LIBRARY_PATH=/usr/local/openssl/lib
export LC_ALL="en_US.UTF-8"
export LDFLAGS="-L/usr/local/openssl/lib -Wl,-rpath,/usr/local/openssl/lib"
eof
source /etc/profile.d/openssl.sh
# 继续编译tengine,再次报错,缺失zlib库
apt install zlib1g-dev -y
# 报错缺失libxml2/libxslt
apt install libxslt1-dev libxml2-dev -y
# 报错缺失gd库
apt install libgd-dev -y
# 报错缺失 geoip 库
apt install libgeoip-dev -y
# 接下来没有报错了,configure完成后,继续安装
make && make install
# 编译报错,make[1]: *** [objs/Makefile:1987: /usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127
# 修改编辑配置文件
vim 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/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
# 重新编译安装一遍,安装就完成了
nginx -t
# 报错,/var/cache/nginx/client_temp 不存在,手动创建一下目录
mkdir -p /var/cache/nginx/
大功告成
编译过程中遇到许多依赖缺失,Ubuntu系统与centos不一样,centos下可以直接安装缺失依赖,Ubuntu下依赖包名字是不同的,如gcc-c++,centos可以直接安装,Ubuntu需要安装g++。 后续可以配置tengine,将业务反向代理出去,统一使用80端口发布,用域名区分业务。