我正在使用xterm.js和chalk.js在我用作个人网站的 Web 终端中创建彩色字符串。
当我在本地运行它时,它会根据需要工作:
但是当我在生产中运行它时,颜色消失了:
要将xterm.js与后端连接,我使用socket.io,当我调试它时,我看到了客户端收到的差异
- 当地的:
socket.io-client:socket calling ack 4 with
[{"text":"\n\u001b[1m\u001b[33m----- Jobs detailed description -----\u001b[39m\u001b[22m\n
- 与产品:
socket.io-client:socket calling ack 4 with
[{"text":"\n----- Jobs detailed description -----\n
正如您在 prod 中看到的,所有由chalk.js添加的 ANSI 转义码都消失了。
我的 Nginx 服务器配置为反向代理以访问我的 NodeJS 的后端,我怀疑配置错误导致 Nginx “吃掉”所有 ANSI 转义码。
我需要在我的 Nginx 配置文件中更改什么以通过 ANSI 转义码?
- 我的 Nginx 配置在这里(它是我的域的配置
enabled-sited
notnginx.conf
:
server {
listen 80;
listen [::]:80;
root /var/www/anatoly.dev/html;
charset utf-8;
charset_types *;
index index.html index.htm index.nginx-debian.html;
server_name anatoly.dev www.anatoly.dev;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /socket.io {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_cache_bypass $http_upgrade;
}
}
- 我的
nginx.conf
:
user ******;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
charset utf-8;
charset_types *;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}