gin 实现首页不缓存

在 gin 中实现首页不缓存 之前提到了在 nginx 中添加响应头 Cache-Control: no-cache 不缓存首页, 以便每次发布 CDN 都能回源到最新的资源。 nginx 的配置可能都是实施人员的操作, 或许不在掌控范围内。 自己控制起来很简单, 无非就是加一个 Header 头嘛。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 package main import ( "fmt" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() // 一……

阅读全文

配置文件初始化思路一二三

配置文件初始化思路要点一二三 配置文件字段如下 1 2 3 4 type Config struct { Server Server `json:"server,omitempty" yaml:"server,omitempty"` Ingresses netv1.IngressSpec `json:"ingresses,omitempty" yaml:"ingresses,omitempty"` } 完整配置如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 server: port: 8080 ingresses: rules: - host: www.baidu.com http: paths: - backend: service: name: /search port: number: 80 pathType: ImplementationSpecific # pathType: Exact # pathType: Prefix Config 文件 读取多个文件后合并最终结果。 可以将不同的功能配置放在不同的文件中, 在数据内容多的情况下更有利于操作。……

阅读全文

nginx 实现首页不缓存

nginx 实现首页不缓存 前端上 CDN 加速, 后端上 DCDN, 加速网站访问速度。 前端代码编译的时候, 可以加上 hash 值使编译后的产物名字随机, 可以在不刷新 CDN 资源 的情况下, 保障页面展示最新。 虽然对多了一点回源, 但减少了人工操作。 但是 首页不能被缓存, 否则于事无补。 对于首页的缓存设置, 有一点注意事项, 其一 ,……

阅读全文

v2ray 配置

v2ray 配置 命令行快捷键 pxy='http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890 $@' client.json 同时监听 socks5 和 http 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 { "log": { "error": "", "loglevel": "info", "access": "" }, "inbounds": [ { "listen": "127.0.0.1", "protocol": "socks", "settings": { "udp": false, "auth": "noauth"……

阅读全文

设置 docker server 网络代理

如果在国内使用docker, 大家一般会配置各种加速器, 我一般会配置阿里云或腾讯云,还算比较稳定。 /etc/docker/daemon.json 配置如下 1 2 3 4 5 6 7 8 { "registry-mirrors": [ "https://mirror.ccs.tencentyun.com", "https://wlzfs4t4.mirror.aliyuncs.com" ], "bip": "169.253.32.1/24", "data-root": "/data/docker/var/lib/docker" } 上述配置, 对 docker.io 的镜像加速效果很好, 但对 google 镜像的加速效果就很差了比如k8s相关的以gcr.io或quay.io开头的镜像地址。 这个时候可以……

阅读全文

typescript 将 json 序列化为 querystring 格式

typescript 将 json 序列化为 querystring 格式 使用 typescript 时, 需要同时安装 @types/qs 和 qs 1 yarn add @types/qs qs demo 1 2 3 4 5 6 7 8 9 const params = qs.stringify({ namespace: namespace, replicas: replicas, }) const u = `/deployments/${name}/replicas?${params}` console.log("Uuuuu::::", u); // Uuuuu:::: /deployments/failed-nginx/replicas?namespace=default&replicas=3……

阅读全文

vue3 安装 vue-router 支持

安装 vue-router 路由支持 在 vue3 中使用的是 vue-router@next 版本 ^4.y.z 1 yarn add vue-router@next /src/router/index.ts 创建路由规则 安装之后, 在创建文件 /src/router/index.ts 作为 vue-router 的初始化文件。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // 导入创建路由所需的组件 import { createRouter, createWebHistory } from "vue-router"; // 路由目标组件 import HelloWorld from '../components/HelloWorld.vue' import World from '../components/World.vue' // 路由表 const routes = [ { path: "/helloworld", name: "HelloWorld", component: HelloWorld }, { path: "/world", name: "World", component: World } ] // 创……

阅读全文

vue3 使用 @ 路径别名

使用 @ 路径别名 在使用 import 的时候, 可以使用相对路径 ../components/HelloWorld.vue 指定文件位置, 但这依赖文件本身的位置,在 跨目录 的时候, 并不方便。 例如, 路由文件 要使用 Components 组件 1 2 3 4 // file: /src/router/index.ts // 路由目标组件 import HelloWorld from '../components/HelloWorld.vue' import World from '../components/World.vue' 要使用路径别名, 需要进行一些额外配置 安装 @types/node 支持 安装 @types/node 组件 1 yarn add @types/node 在 tsconfig.json 中, compilerOptions 下配置 1 2 3 4 5 6 7 8 9……

阅读全文

gin 内部重定向时 middleware 不可用异常

gin 内部重定向时 middleware 不可用异常 axios 请求时出现 cors error 在使用 axios 请求后端时,遇到 cors 跨域问题, 虽然已经在 gin 中添加了 cors 的 middleware 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 func cors() gin.HandlerFunc { return func(c *gin.Context) { method := c.Request.Method origin := "*" if method != "" { c.Header("Access-Control-Allow-Origin", origin) // 可将将 * 替换为指定的域名 c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization,X-Token") c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type") c.Header("Access-Control-Allow-Credentials", "true") } if method == "OPTIONS" { c.AbortWithStatus(http.StatusNoContent) } } } 问题原因 gin Middleware……

阅读全文

K8S 使用 TTL 控制器自动清理完成的 job pod

K8S 使用 TTL 控制器自动清理完成的 Job Pod 最近为集群 CI 默认添加了 .spec.ttlSecondsAfterFinished 参数, 以便在 cronjob 和 job 运行完成后自动清理过期 pod 。 但是在 CI 的时候却失败, 报错如下。 1 spec.jobTemplate.spec.ttlSecondsAfterFinished: Forbidden: disabled by feature-gate 核查资料得知, 在 v1.21 之前, 该开关默认是关闭的。 刚好错误集群低于此版本。 Job TTL 控制器 K8S 提供了一个 TTL 控制器, 可以自动在 JOB Complete 或 Failed 之后, 经过一定时间……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它