关于kubernetes:Nginx-容器中文字符集

36次阅读

共计 1374 个字符,预计需要花费 4 分钟才能阅读完成。

一. nginx 镜像中文字符集

1. Dockerfile

基于 Debian 12 的 nginx 镜像,默认不反对中文字符集,制作镜像让其中文文件不显示乱码

FROM nginx:latest
RUN sed -i 's#http://deb.debian.org#https://mirrors.163.com#g' /etc/apt/sources.list && apt-get update && apt-get install locales -y && sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen && locale-gen
ENV LC_ALL zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
docker build . -t harbor.uuf.net.cn/library/nginx:ch-cn

2. Deploy

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-warehouse
  namespace: nokf
spec:
  storageClassName: managed-nfs-storage
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-warehouse
  namespace: nokf
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-warehouse
  template:
    metadata:
      labels:
        app: nginx-warehouse
    spec:
      containers:
      - name: nginx-warehouse
        image: harbor.uuf.net.cn/library/nginx:ch-cn
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /etc/nginx/conf.d/
          name: nginx-warehouse
        - mountPath: /home/nginx-warehouse
          name: storage
      volumes:
      - name: nginx-warehouse
        configMap:
          name: nginx-warehouse
      - name: storage
        persistentVolumeClaim:
          claimName: nginx-warehouse
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-warehouse
  namespace: nokf
spec:
  type: ClusterIP
  ports:
    - port: 80
  selector:
    app: nginx-warehouse
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-warehouse
  namespace: nokf
data:
  default.conf: |-
    server {
        listen 80;
        location / {
           autoindex on;
           charset utf-8;    # 必要的
           root /home/nginx-warehouse/;
        }
    }

正文完
 0