Linux,Kubernetes

基于nginx反代部署 jsdelivr 镜像站 In Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jsd
  labels:
    app: jsd
spec:
  replicas: 2
  template:
    metadata:
      name: jsd
      labels:
        app: jsd
    spec:
      containers:
        - name: jsd
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              protocol: TCP
              name: http
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "1000m"
              memory: "1024Mi"
          volumeMounts:
            - name: config
              mountPath: /etc/nginx/conf.d
              readOnly: false
      volumes:
        - name: config
          persistentVolumeClaim:
            claimName: jsd-data
      restartPolicy: Always
  selector:
    matchLabels:
      app: jsd
---
apiVersion: v1
kind: Service
metadata:
  name: jsd
spec:
  selector:
    app: jsd
  ports:
    - port: 80
  type: NodePort
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jsd-data
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: "nfs-storage"  #你的StorageClass名
  resources:
    requests:
      storage: 1Gi

nginx配置文件

server {

    listen 80;

    #listen 443 ssl http2;

    # 请更改为你的证书路径
    #ssl_certificate certs/default.cer;
    #ssl_certificate_key certs/default.key;

    # 请更改为你的镜像域名
    server_name cdn.ipip.icu;

    location / {
        proxy_pass https://cdn.jsdelivr.net;
        proxy_set_header Host $proxy_host;
        proxy_set_header Accept-Encoding '';
        proxy_ssl_server_name on;
        proxy_ssl_name $proxy_host;
        proxy_redirect / /;
        # Proxy Cache
        proxy_cache jsdelivr;
        proxy_cache_lock on;
        proxy_cache_lock_timeout 15s;
        proxy_cache_use_stale updating;
        proxy_cache_background_update on;
        proxy_cache_key $host$request_uri;
        proxy_cache_valid 200 301 302 30d;
        proxy_cache_valid 500 501 502 503 15s;
        proxy_cache_valid any 5m;
        # Replace Domain
        sub_filter_once off;
        sub_filter_types application/javascript application/json text/xml text/css;
        # cdn.ipip.icu替换为你自己的域名
        sub_filter 'cdn.jsdelivr.net'  'cdn.ipip.icu'; 
    }

}

# 缓存路径请根据需要更改
proxy_cache_path /root levels=1:2 use_temp_path=off keys_zone=jsdelivr:300m inactive=30d max_size=1g;

将nginx配置文件放到该deployment挂载出来的目录中,然后重启服务即可

效果展示

本站jsd镜像站

回复

  1. kuludi kuludi
    Chrome 102 10

    之前不是网易云热评吗 怎么换博客了

    1. grpc grpc
      Chrome 102

      网易云那边爬取失效啦 就换成博客了

This is just a placeholder img.