You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Elastic Beanstalk环境变量日文显示问号问题求助

解决AWS Elastic Beanstalk环境变量日文显示问号的问题

1. 强制系统级UTF-8编码

在项目根目录新建.ebextensions文件夹,创建01-set-encoding.config配置文件,写入以下内容:

commands:
  set_lc_all:
    command: echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
  set_lang:
    command: echo "export LANG=en_US.UTF-8" >> /etc/profile

该配置会在EC2实例启动时设置系统默认编码为UTF-8,避免环境变量读取时出现编码混乱。

2. 适配应用服务器编码设置

根据你使用的应用服务器,添加对应配置:

  • Java/Tomcat:在.ebextensions里创建02-tomcat-encoding.config:
container_commands:
  update_tomcat_opts:
    command: echo 'JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8"' >> /opt/tomcat/bin/setenv.sh
  • Python/Gunicorn:修改项目中的Procfile,在启动命令前指定编码:
web: LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 gunicorn --bind=0.0.0.0:8000 app:app
  • Node.js:在.ebextensions添加03-node-encoding.config:
commands:
  set_node_env_encoding:
    command: echo "export LC_ALL=en_US.UTF-8" >> /etc/profile.d/nodejs.sh

3. 重新部署并验证

把配置文件添加到项目后,重新部署到Elastic Beanstalk。部署完成后可以登录EC2实例,执行echo $LANG和echo $LC_ALL,确认输出为en_US.UTF-8。之后重新设置日文环境变量,在应用里打印变量值,检查是否正常显示日文。

内容的提问来源于stack exchange,提问作者S Khttak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 16:48:25