【问题标题】:Nginx http_accept cannot be mapped to variable for content-negotiationNginx http_accept 无法映射到内容协商的变量
【发布时间】:2017-09-28 20:12:51
【问题描述】:

目标是使用 - 将Content-Type 值映射到文件类型

# nginx.conf
map $http_accept $suffix {
    "~*turtle" ".ttl";
    default    "DEFAULT";
}

由 - 处理

# sites-available/site
location /ontologies {
    root /folder;
    add_header Vary Accept;
    add_header X-debug-accept "$http_accept";
    add_header X-debug-suffix "$suffix";
    try_files $uri$suffix $uri =404;
}

但是,响应总是给出 -

# curl -I -H "Content-type: text/turtle" URL
http_accept = */*
suffix      = DEFAULT, which is actually (blank)

【问题讨论】:

    标签: nginx mime-types content-type


    【解决方案1】:

    您的问题是您访问了错误的标题。你应该使用$http_content_type 而不是$http_accept

    # curl -v -I -H "Content-type: text/turtle" URL
    *   Trying ::1...
    * Connected to localhost (::1) port 80 (#0)
    > GET / HTTP/1.1
    > Host: localhost
    > User-Agent: curl/7.47.0
    > Accept: */*
    > Content-Type: text/turtle
    

    如您所见,您通过了Content-Type 而不是Accept。因此,根据您需要使用的标头使用正确的变量。 $http_content_type$http_accept

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 2012-02-21
      • 1970-01-01
      • 2011-02-05
      • 2012-08-13
      相关资源
      最近更新 更多