LoginSignup
2
3

More than 3 years have passed since last update.

nginx indexディレクティブ

Posted at

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>
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3