Skip to content

Commit

Permalink
update module
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoBao committed Dec 21, 2023
1 parent e161257 commit 3a1cd69
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 25 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ RUN set -x \
&& make install \
&& curl -fsSL https://github.com/nicholaschiasson/ngx_upstream_jdomain/archive/refs/tags/1.4.0.tar.gz -o ${tempDir}/ngx_upstream_jdomain.tar.gz \
&& tar -zxf ${tempDir}/ngx_upstream_jdomain.tar.gz -C ${tempDir} \
&& git clone https://github.com/zhouchangxun/ngx_healthcheck_module.git ${tempDir}/ngx_healthcheck_module \
&& curl -fsSL https://github.com/alibaba/tengine/archive/${TENGINE_VERSION}.tar.gz -o tengine.tar.gz \
&& tar zxf tengine.tar.gz -C ${tempDir} \
&& cd ${tempDir}/tengine-${TENGINE_VERSION} \
&& patch -p1 < ${tempDir}/ngx_healthcheck_module/nginx_healthcheck_for_tengine_2.3+.patch \
&& ./configure --user=www-data --group=www-data \
--prefix=/etc/nginx --sbin-path=/usr/sbin \
--error-log-path=/var/log/nginx/error.log \
Expand All @@ -80,7 +82,7 @@ RUN set -x \
--with-http_addition_module \
--with-http_v2_module \
#--add-module=./modules/ngx_http_upstream_dynamic_module \
--add-module=./modules/ngx_http_upstream_check_module \
#--add-module=./modules/ngx_http_upstream_check_module \
--add-module=./modules/ngx_http_upstream_session_sticky_module \
--add-module=./modules/ngx_http_upstream_consistent_hash_module \
--add-module=./modules/ngx_http_user_agent_module \
Expand All @@ -92,6 +94,7 @@ RUN set -x \
--add-module=./modules/ngx_http_lua_module \
--add-module=./modules/ngx_http_reqstat_module \
--add-module=${tempDir}/ngx_upstream_jdomain-1.4.0 \
--add-module=${tempDir}/ngx_healthcheck_module \
--with-http_geoip_module=dynamic \
--with-stream \
&& make && make install \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
* 新增 “重新应用配置” 功能,可以手动重新渲染或重载 Nginx 配置,默认重新渲染,选择取消后可选择仅重载配置
* 新增 stream 模块中 proxy_timeout 1800s 固定配置项
* 新增 check_shm_size 32M 固定配置项
* 新增 HTTP 类型规则后端节点域名动态检测 [ngx_upstream_jdomain](https://github.com/nicholaschiasson/ngx_upstream_jdomain) 实现,防止 upstream 域名 IP 变动,仅支持 HTTP 协议
* 新增 规则列表分页长度配置,默认 10 条,可配置 10-100 条分页
* 新增 测试支持 ARM 架构,pull 镜像可以使用 `--platform linux/arm64` 参数
* 新增 HTTP 类型规则后端节点域名动态检测 [ngx_upstream_jdomain](https://github.com/nicholaschiasson/ngx_upstream_jdomain) 实现,防止 upstream 域名 IP 变动,仅支持 HTTP 协议
* 新增 更换主动健康检测模块 [ngx_healthcheck_module](https://github.com/zhouchangxun/ngx_healthcheck_module),以解决动态域名模块兼容性问题,并增加 TCP 规则的后端节点检测功能
* 修复 在 SSL 状态下打开后端域名开关不生效的问题
* 修复 部分情况下配置错误导入失败无法回滚的 Bug,优化了导入逻辑,略微提升了导入速度
* 修复 其他交互 Bug
Expand Down
4 changes: 2 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from settings.models import system_settings, sync_status
from settings.views import save_sync, get_config, import_config
from django_filters import rest_framework as filters
from nginx.views import get_sys_info, get_sys_status, get_req_status, get_proxy_http_status
from nginx.views import get_sys_info, get_sys_status, get_req_status, get_proxy_upstream_status
from datetime import datetime
import logging

Expand Down Expand Up @@ -74,7 +74,7 @@ def get_upstream_status(self, request):
> 参数同 `/proxy/` API
"""
config_id = request.query_params.get('config_id')
upstream_status = get_proxy_http_status()
upstream_status = get_proxy_upstream_status()
if config_id:
p = proxy_config.objects.filter(config_id=config_id).filter(protocol=True)
if p:
Expand Down
11 changes: 6 additions & 5 deletions nginx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,20 @@ def post_request(url, headers={}):
resp = None
return resp

def get_proxy_http_status():
def get_proxy_upstream_status():
url = "http://127.0.0.1/up_status?format=json"
resp = post_request(url)
_ret = []
if resp:
ret = post_request(url).json()
if 'servers' in ret:
server = ret['servers']['server']
if server:
_ret = [ d for d in server if d.get('name') != "NGX_UPSTREAM_JDOMAIN_BUFFER" ]
http_server = ret['servers']['http']
stream_server = ret['servers']['stream']
if stream_server or http_server:
_ret = [ d for d in http_server if d.get('name') != "NGX_UPSTREAM_JDOMAIN_BUFFER" ] + stream_server
else:
_ret = []

return _ret

def get_req_status():
Expand Down
2 changes: 1 addition & 1 deletion proxy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
url(r'^$', views.view),
url(r'^save/$', views.save),
url(r'^status/$', views.change_status),
url(r'^checkhttp/$', views.check_http_status),
url(r'^upstream_health/$', views.check_upstream_status),
url(r'^delete/$', views.delete_proxy),
url(r'^query/$', views.query_proxy),
url(r'^gen_config/$', views.gen_config),
Expand Down
4 changes: 2 additions & 2 deletions proxy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def view(request):
pass

@is_auth
def check_http_status(request):
def check_upstream_status(request):
try:
post = json.loads(request.body.decode('utf-8'))
status = get_proxy_http_status()
status = get_proxy_upstream_status()

if post['pk'] == 0:
content = { "flag":"Success","status":status}
Expand Down
2 changes: 1 addition & 1 deletion resource/nginx/nginx.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ http {
}

location /up_status {
check_status;
healthcheck_status json;
allow 127.0.0.1;
deny all;
}
Expand Down
2 changes: 1 addition & 1 deletion resource/nginx/nginx.template
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ http {
server_name 127.0.0.1;

location /up_status {
check_status;
healthcheck_status json;
allow 127.0.0.1;
deny all;
}
Expand Down
4 changes: 1 addition & 3 deletions resource/nginx/proxy.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ upstream {{ proxy.config_id | lower }} {
{%- endif %}
{%- for server in upstream %}
{%- if proxy.backend_dynamic_domain %}
jdomain {{ server.address }}:{{ server.port }} interval=60;
jdomain {{ server.address }} port={{ server.port }} ipver=4;
{%- else %}
server {{ server.address }}:{{ server.port }} weight={{ server.weight }};
{%- endif %}
{%- endfor %}
{%- if proxy.protocol %}
{%- if proxy.http_check %}
{%- if proxy.backend_protocol == 'https' %}
check interval=3000 rise=2 fall={{ proxy.max_fails }} timeout={{ proxy.fail_timeout * 1000 }} type=ssl_hello;
Expand All @@ -26,7 +25,6 @@ upstream {{ proxy.config_id | lower }} {
check interval=3000 rise=2 fall={{ proxy.max_fails }} timeout={{ proxy.fail_timeout * 1000 }} type=tcp;
check_keepalive_requests 100;
{%- endif %}
{%- endif %}
}
{%- endif %}

Expand Down
12 changes: 4 additions & 8 deletions templates/proxy/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="proxy_status_title">节点 HTTP 服务状态</h4><small
<h4 class="modal-title" id="proxy_status_title">后端节点状态</h4><small
id="proxy_status_mtitle"></small>
</div>
<div class="modal-body">
Expand Down Expand Up @@ -477,14 +477,10 @@ <h4 class="modal-title" id="edit_balancer_title"></h4><small id="edit_balancer_m
<button type="button" title="{{ server.config_id }}" name="proxy_upstream_status" class="btn btn-xs"
onclick="proxy_status('{{ server.pk }}',0)">HTTP</button>
</td>
{% elif server.protocol and not server.http_check and not server.to_domain_toggle %}
{% elif not server.http_check and not server.to_domain_toggle %}
<td>
<button type="button" title="{{ server.config_id }}" name="proxy_upstream_status" class="btn btn-xs" onclick="proxy_status('{{ server.pk }}',0)">TCP</button>
</td>
{% elif not server.protocol %}
<td>
<button type="button" class="btn btn-primary btn-xs" disabled>TCP</button>
</td>
{% else %}
<td>
<button type="button" class="btn btn-primary btn-xs" disabled>None</button>
Expand Down Expand Up @@ -918,7 +914,7 @@ <h4 class="modal-title" id="edit_balancer_title"></h4><small id="edit_balancer_m
if (getdata == 1) {
jQuery.ajax({
type: 'post',
url: '/proxy/checkhttp/',
url: '/proxy/upstream_health/',
data: JSON.stringify(post),
dataType: "json",
success: function (p) {
Expand Down Expand Up @@ -962,7 +958,7 @@ <h4 class="modal-title" id="edit_balancer_title"></h4><small id="edit_balancer_m
var upstream_status;
jQuery.ajax({
type: 'post',
url: '/proxy/checkhttp/',
url: '/proxy/upstream_health/',
data: JSON.stringify(post),
async: false,
dataType: "json",
Expand Down

0 comments on commit 3a1cd69

Please sign in to comment.