uwsgi+nginx+flask+docker+supervisord oracle中文乱码问题

目前uwsgi+nginx+flask+docker+supervisord 部署系统的是否,出现了一个比较奇特的中文乱码问题
基础镜像使用https://github.com/tiangolo/uwsgi-nginx-flask-docker 具体也查看了dockerfile
并没发现特别的地方.
以下是项目的配置

nginx

 
server{
    listen 80;
    root /app/dist/;
    charset utf-8;
    access_log /var/log/nginx_access.log;
    error_log /var/log/nginx_error.log;
    location / {
        try_files $uri $uri/ /index.html;
    }
    location ~/api/ {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:5000;
    }
}

uwsgi原始配置

[uwsgi]
chdir = /app
wsgi-file = app.py
callable = app
master = true
socket = 0.0.0.0:5000
processes = 4
threads = 2
max-requests = 1000
harakiri = 30
post-buffering = 8192
post-buffering-bufsize = 65535
buffer-size = 65535
pidfile = uwsgi.pid
logger = file:/app/uwsgi.log
JSON_AS_ASCII = false

supervisord 配置

[supervisord]
nodaemon=true
[program:uwsgi]
command=uwsgi --ini /etc/uwsgi/uwsgi.ini
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=/usr/sbin/nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
# Graceful stop, see http://nginx.org/en/docs/control.html
stopsignal=QUIT

包含oracle client 的镜像镜像

相关oracle sdk,参考 https://www.cnblogs.com/rongfengliang/p/11234255.html

FROM tiangolo/uwsgi-nginx-flask:python3.5
# Oracle instantclient
ADD oracle/instantclient-basic-linux.x64-12.2.0.1.0.zip /tmp/instantclient-basic-linux.x64-12.2.0.1.0.zip
ADD oracle/instantclient-sdk-linux.x64-12.2.0.1.0.zip /tmp/instantclient-sdk-linux.x64-12.2.0.1.0.zip
ADD oracle/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip /tmp/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
RUN apt-get update -y && apt-get install libaio-dev unzip locales -y
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN unzip /tmp/instantclient-basic-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN unzip /tmp/instantclient-sdk-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN unzip /tmp/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN ln -s /usr/local/instantclient_12_2 /usr/local/instantclient
RUN ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so
RUN ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus
RUN apt-get clean -y 
ENV ORACLE_HOME=/usr/local/instantclient
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/instantclient
RUN rm -rf /tmp

问题解决思路

单独使用python 命令启动没问题,oracle 相关的编码配置没问题,大家常说的
如下编码配置,都是可以的

 
import os 
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' 

以为是supervisord 环境变量的问题,独立启动uwsgi还是同样的问题,从本能的思考就是
这个肯定是编码的问题,实际上就是编码的问题,理论上代码上已经配置NLS_LANG了,为啥
还是不行呢,如果看了上边的基础镜像,会发现我们已经包含了语言包,但是还是没有解决,然后
就猜想可能是那个配置需要环境变量,对于uwsgi环境变量可以通过env 配置,所以参考python代码
修改env= NLS_LANG='SIMPLIFIED CHINESE_CHINA.UTF8', 运行发现提示

 
Cannot access NLS data files or invalid environment specified

一下子就感觉有戏,然后参考相关oracle client 配置,修改为env = NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
再次运行问题解决,实际上配置系统环境变量也是可以的,同时python 已经配置了,为什么uwsgi还需要呢,看来还是
需要仔细研究下uwsgi的原理了

参考资料

https://blog.csdn.net/qq_20221151/article/details/83449615
https://github.com/tiangolo/uwsgi-nginx-flask-docker
https://www.cnblogs.com/rongfengliang/p/11234255.html
https://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/WSGIquickstart.html

posted on   荣锋亮  阅读(516)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-04-04 使用deb 打包开发的postgres extension 另外一种方法
2019-04-04 使用deb 打包开发的postgres extension
2019-04-04 ubuntu deb pacakge 开发
2019-04-04 What’s New In GRANDstack?
2017-04-04 lua resty template && openresty 使用
2017-04-04 jekyll 安装使用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示