Skip to content

技术储备不够, Nginx 先顶上 ​

traefik 与 k8s 的技术沉淀不足。。。nginx 先顶上

问题 ​

gzip ​

traefik 的 gzip 压缩功能,是黑名单模式,默认所有的响应类型都会压缩。而 nginx 是白名单模式,在名单内的才会压缩。。。更偏向于使用 nginx 的这种配置方式。

websocket ​

个别应用 直接配 应用路由,无法正常使用 websocket 相关的功能。可以把 应用路由 配置到 nginx 上,通过 nginx 转发一层。

traefik 中间件 不知道怎么配才正规 ​

前面试过在 traefik 中间件 中配置 IP白名单、请求体大小限制 等。

但是在 k3s 环境下,traefik 作为内置组件,由 k3s 管理 traefik 的安装与升级。kuboard 上直接添加中间件,似乎不太正规。在集群 升级、重启 等情况下,中间件的配置可能导致 traefik 组件运行出错。

@装机必备/nginx ​

nginx ​

tcp 代理

nginx
stream {
    server {
        listen 1883;
        proxy_pass tb-node:1883;
        
        proxy_connect_timeout 10s;
    	proxy_timeout 65s;
    }
}

真实ip, 大请求体, 大请求头, gzip, https, websocket, IP白名单

nginx
set_real_ip_from 10.0.0.0/8;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 192.168.0.0/16;
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

client_max_body_size 1G;
large_client_header_buffers 4 16k;

gzip on;
gzip_min_length 1k;
gzip_vary on;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/html text/css text/javascript application/javascript application/json text/xml application/xml application/xml+rss image/svg+xml application/font-sfnt;

server {
    listen 80;
    server_name git.apihub.net;

	set $allow_ip 0;
	if ($remote_addr ~ ^(10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|192\.168\.)) {
    	set $allow_ip 1;
	}
    if ($remote_addr = xx.xx.xx.xx) { set $allow_ip 1; }
    if ($allow_ip = 0) {
        return 403;
    }

    if ($http_user_agent ~* "bot|facebook") {
        return 403;
    }
    location /robots.txt {
        return 200 'User-agent: *\nDisallow: /';
    }
    location / {
        proxy_pass http://10.168.1.100:8418;
        
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_redirect http:// https://;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}