docker 容器web站点 中文文件名访问404问题

一,排查问题经过

1. 检查文件实际名称

在服务器上使用命令确认文件名的实际编码:

2. 系统字符编码设置

确保服务器系统支持UTF-8编码:

java 复制代码
# 检查当前语言环境
locale
# 输出应包含类似:LANG=en_US.UTF-8 或 LANG=zh_CN.UTF-8

# 临时设置为UTF-8(针对当前会话)
export LANG=en_US.UTF-8

# 永久设置:编辑 /etc/environment,添加:
LANG=en_US.UTF-8

3. Web服务器配置

Nginx

在配置文件中明确指定UTF-8编码:

java 复制代码
server {
    charset utf-8;
    ...
}

然而这些改了都没生效还是404

二,最终结果

最后在tomcat的脚本文件catalina.sh文件中加入 . /etc/profile 命令后,重启容器就可以识别到中文文件名了。(重点加. /etc/profile 命令)

javascript 复制代码
# 编辑启动脚本,改用直接设置环境变量
vi /opt/datacenter/project/biframe/start.sh
java 复制代码
# head /usr/local/tomcat/bin/catalina.sh 
#!/bin/sh
. /etc/profile

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at

强制重启

javascript 复制代码
# 强制停止
pkill -9 -f biframe.jar

# 等待几秒确保进程停止
sleep 3

# 重新启动
cd /opt/datacenter/project/biframe/
./start.sh
相关推荐
霍霍的袁15 小时前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
彧azz15 小时前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
玉&心15 小时前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing15 小时前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
孙启超15 小时前
【AI开发之Rust】第 11 课:智能指针与内部可变性
开发语言·后端·rust
此生决int16 小时前
深入理解C++系列(20)——C++11(下)
开发语言·c++
-梅16 小时前
linux(8) 软硬链接
linux·运维·服务器
guo_wen_qiang16 小时前
上传本地镜像到harbor中
docker·容器·持续部署
AIgorithmGEEK16 小时前
[Linux]线程三部曲(上):一个执行流的诞生——从操作系统一路拆到 pthread_create
linux·线程·pid
羑悻的小杀马特16 小时前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作