nginx indexディレクティブを調べた。
indexディレクティブはpathが/の時に、pathにファイル名を付与して内部リダイレクトしてくれる。
デフォルトはindex index.html
nginx.conf
location / {
index hoge.txt;
}
上記confの場合、
hoge.txt(aaa)を用意して/
にアクセスするとhoge.txtが返却される。
$ curl localhost
aaa
$ curl localhost/
aaa
$ curl localhost/hoge.txt
aaa
$ curl localhost/dummy
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>
hoge.txtがない場合は↓になる。404はわかるけどなぜ403になるのだろう?
$ curl localhost
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>
$ curl localhost/
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>
$ curl localhost/hoge.txt
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>
$ curl localhost/dummy
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>