代码之家  ›  专栏  ›  技术社区  ›  coolharsh55

Nginx http\u accept无法映射到用于内容协商的变量

  •  1
  • coolharsh55  · 技术社区  · 7 年前

    目标是获得地图 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)
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Tarun Lalwani    7 年前

    $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\u内容类型 $http\u接受