0

我们有一个使用 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;
4

1 回答 1

1

你试过proxy_pass_header在 nginx 中使用吗?

proxy_pass_header Content-Type;

http://wiki.nginx.org/HttpProxyModule

顺便说一句-您的问题中似乎您的 nginx 配置可能不完整。

于 2013-01-02T19:56:14.520 回答