nginx

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > nginx > nginx 镜像中文字符集

nginx 镜像中文字符集使用详解

作者:moon

这篇文章主要为大家介绍了nginx 镜像中文字符集使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

一. nginx 镜像中文字符集

1. Dockerfile

基于 Debian 12 的nginx镜像,默认不支持中文字符集,制作镜像让其中文文件不显示乱码, locale-gen "en-US.UTF-8" "zh-CN.UTF-8"

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/;
        }
    }

以上就是nginx 镜像中文字符集使用详解的详细内容,更多关于nginx 镜像中文字符集的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:
阅读全文