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
相关推荐
wuyk5555 小时前
第2章:六步换相原理全解+STM32工程实战
c语言·开发语言·stm32·单片机·嵌入式硬件
hey_sml5 小时前
JAVA每日一学---CompletableFuture中thenApply与thenCompose区别详解
java·开发语言
数智工坊5 小时前
Zotero自建Ubuntu WebDAV附件同步方案(完美解决存储空间不足)
linux·运维·ubuntu
萧瑟余晖6 小时前
Java深入解析篇十七之SpringCloud
java·开发语言
ltl6 小时前
HTTP/3 实战:从 QUIC 到 H3 的完整请求链路
linux
ltl7 小时前
POSIX 文件锁:flock、fcntl 与 NFS 上的工程陷阱
linux
ltl7 小时前
CUDA 生态:cuBLAS、cuDNN、NCCL、Triton、CUTLASS
linux
饺子大魔王的男人7 小时前
CentOS部署Cockpit:图形化查看系统、日志与服务状态
linux·运维·centos
不会就选b7 小时前
Linux之信号(二)
linux·运维·服务器
ttod_qzstudio7 小时前
Java 常用语法极简通关(五):类与对象——字段、方法、构造器、this 与 static
java·开发语言·python