Tengine解决反向代理动态DNS解析问题

从官方网站可以了解到,ngx_http_upstream_dynamic_module模块提供了在运行时动态解析upstream中server域名的功能。

官方介绍:ngx_http_upstream_dynamic_module - The Tengine Web Server (taobao.org)

不过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模块

2.确认下安装包是否包含这个模块,安装包可以从GitHub - alibaba/tengine: A distribution of Nginx with some advanced features下载

[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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Tengine是一个基于Nginx的Web服务器,具有高性能和高可靠性。如果您想将Tengine用作代理服务器,可以使用以下步骤进行单机代理替换Nginx: 1. 安装Tengine 请根据您的操作系统在Tengine官方网站下载适当的二进制文件,并按照说明进行安装。 2. 配置Tengine Tengine的配置文件与Nginx的配置文件类似。您需要根据您的需求修改Tengine的配置文件。通常,您需要修改Tengine的监听端口、代理目标地址和代理请求头等。 3. 启动Tengine 在修改完配置文件后,您可以通过Tengine的命令行工具启动Tengine。如果一切正常,您将看到Tengine已经开始了工作。 如果您想将Tengine用作集群代理服务器,可以使用以下步骤进行Nginx替换: 1. 安装Tengine 您需要在所有服务器上安装Tengine。请根据您的操作系统在Tengine官方网站下载适当的二进制文件,并按照说明进行安装。 2. 配置Tengine 与单机代理类似,您需要根据您的需求修改Tengine的配置文件。不同之处在于,您需要将所有Tengine实例的配置文件保持一致。 3. 配置负载均衡 您需要使用Tengine或其他负载均衡软件配置所有Tengine实例的负载均衡。负载均衡软件可以根据不同的负载均衡算法选择最佳的Tengine实例。 4. 启动Tengine 在修改完配置文件后,您可以通过Tengine的命令行工具启动所有Tengine实例。如果一切正常,您将看到所有Tengine实例已经开始了工作,并且负载均衡软件已经开始工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值