【问题标题】:return content-type response headers with a node app behind nginx使用 nginx 后面的节点应用程序返回内容类型响应标头
【发布时间】:2012-12-16 14:36:30
【问题描述】:

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

【问题讨论】:

    标签: node.js nginx express


    【解决方案1】:

    你试过在 nginx 中使用proxy_pass_header 吗?

    proxy_pass_header Content-Type;

    http://wiki.nginx.org/HttpProxyModule

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

    【讨论】:

      猜你喜欢
      • 2016-09-07
      • 1970-01-01
      • 2012-12-16
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      • 2021-05-23
      • 1970-01-01
      相关资源
      最近更新 更多