我们有一个使用 node js(express js)构建的 web 应用程序,它位于 nginx 后面。
对于特定的 API,我们希望内容类型响应标头为“text/plain”。对于此以下代码在控制器中。
res.setHeader('Content-Type', 'text/plain'); res.send(响应);
当服务器不在 nginx 之后时,这有效。但是当服务器在 nginx 后面时,响应头仍然是 'application/json'
我的 nginx 配置如下所述:
#kZyguser www-data;
user root;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 20000;
# multi_accept on;
}
http {
##
# Basic Settings
##
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;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
client_max_body_size '10M';
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server{
location / {
proxy_pass_header text-plain;
}
}
}