Nginx 反向代理设置 UTF-8 编码 - 使用 proxy_set_header 指令
要在 Nginx 反向代理中设置 UTF-8 编码,可以使用 proxy_set_header 指令来设置。具体步骤如下:
- 打开 Nginx 配置文件
首先需要打开 Nginx 的配置文件,一般在 /etc/nginx/nginx.conf 或者 /etc/nginx/conf.d/default.conf 中。
- 添加
proxy_set_header指令
在 Nginx 配置文件中,找到反向代理的 location 指令,然后添加如下 proxy_set_header 指令:
proxy_set_header Accept-Encoding '';
proxy_set_header Accept-Language 'en-US,en;q=0.5';
proxy_set_header Content-Type 'text/html; charset=utf-8';
这三行指令分别用于禁用 Accept-Encoding,设置 Accept-Language 为英语,设置 Content-Type 为 text/html 并指定字符集为 UTF-8。
- 保存配置文件并重启 Nginx 服务
保存配置文件后,执行 sudo systemctl reload nginx 或者 sudo service nginx reload 命令来重启 Nginx 服务。
这样就完成了在 Nginx 反向代理中设置 UTF-8 编码的操作。
原文地址: https://www.cveoy.top/t/topic/nG2c 著作权归作者所有。请勿转载和采集!