从官方网站可以了解到,ngx_http_upstream_dynamic_module模块提供了在运行时动态解析upstream中server域名的功能。
不过Tengine从2.3开始模块默认是没有编译的,需要自己编译。以下示例中/app/tengine/是我测试环境tengine的安装路径,自己的自行适配调整。
1.检查自己的Tengine编译配置
[root@VM-4-10-centos tengine]# /app/tengine/sbin/nginx -V
Tengine version: Tengine/2.3.1
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: –user=nginx –group=nginx –prefix=/app/tengine –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module
确认configure arguments没有添加ngx_http_upstream_dynamic_module模块
[root@VM-4-10-centos tengine]# ll /root/tengine-2.3.1/modules/
total 80
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_backtrace_module
drwxrwxr-x 3 root root 4096 Jun 26 2019 ngx_debug_pool
drwxrwxr-x 3 root root 4096 Jun 26 2019 ngx_debug_timer
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_concat_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_footer_filter_module
drwxrwxr-x 9 root root 4096 Jun 26 2019 ngx_http_lua_module
drwxrwxr-x 3 root root 4096 Jun 26 2019 ngx_http_proxy_connect_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_reqstat_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_slice_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_sysguard_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_tfs_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_trim_filter_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_upstream_check_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_upstream_consistent_hash_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_upstream_dynamic_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_upstream_dyups_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_upstream_keepalive_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_upstream_session_sticky_module
drwxrwxr-x 2 root root 4096 Jun 26 2019 ngx_http_user_agent_module
drwxrwxr-x 3 root root 4096 Jun 26 2019 ngx_slab_stat
[root@VM-4-10-centos tengine]#
3.编译配置(原有的configure arguments拷贝不变,添加module)
[root@VM-4-10-centos tengine]# cd /root/tengine-2.3.1/
[root@VM-4-10-centos tengine-2.3.1]# ./configure –user=nginx –group=nginx –prefix=/app/tengine –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –add-module=/root/tengine-2.3.1/modules/ngx_http_upstream_dynamic_module
4.编译并安装
[root@VM-4-10-centos tengine]#make && make install
5.再次确认当前的配置
[root@VM-4-10-centos tengine]# /app/tengine/sbin/nginx -V
Tengine version: Tengine/2.3.1
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: –user=nginx –group=nginx –prefix=/app/tengine –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –add-module=/root/tengine-2.3.1/modules/ngx_http_upstream_dynamic_module
显示已添加了
6.修改nginx.conf
[root@VM-4-10-centos tengine]vi conf/nginx.conf
user root;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
gzip on;
server_names_hash_bucket_size 64;
upstream test-api {
dynamic_resolve fallback=stale fail_timeout=10s;
server jst.com;
}
server {
listen 443;
location / {
proxy_pass https://test-api;
}
}
}
7.检查配置并重启
[root@VM-4-10-centos tengine]# ./sbin/nginx -t
nginx: the configuration file /app/tengine/conf/nginx.conf syntax is ok
nginx: configuration file /app/tengine/conf/nginx.conf test is successful
[root@VM-4-10-centos tengine]# ./sbin/nginx -s reload
原文链接:https://blog.csdn.net/qcm0623/article/details/127746478