【发布时间】:2018-08-04 19:08:35
【问题描述】:
我写了这个/etc/nginx/conf.d/apply.conf 并启动了 nginx。
server {
location = /hoge {
return 200;
}
}
但是 curl 命令失败了。
curl localhost:80/hoge
上面写着
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.13.9</center>
</body>
</html>
日志是
open() "/usr/share/nginx/html/hoge" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /hoge HTTP/1.1", host: "localhost"
我只想返回没有响应正文或响应正文空白的状态代码。
我改成这个还是不行。
location /hoge {
return 200 'Wow';
add_header Content-Type text/plain;
}
也试过这个。
location /hoge {
return 200 'Wow';
default_type text/plain;
}
【问题讨论】:
-
location块很好,但您将其放入错误的server块中。请参阅hownginxprocesses a request 了解更多信息。 -
谢谢。我找到了它不工作的原因,这就是你所说的。
-
@KeKe 能否请您发布原因是什么,这会有所帮助。我遇到了同样的问题,尝试了您发布的所有内容以及更多内容,但仍然无法弄清楚问题所在。
标签: http nginx http-status-code-404 nginx-location nginx-status