首頁  >  問答  >  主體

centos - nginx設定location的時候index不起作用?

nginx.conf檔案中有這一段
server {

    listen       80;
    server_name  hello.test.com;

    location / {
        root   html;
        index  index.html index.htm;
    }

    location /aa {
        root   /data1/htdocs/hello.test.com;
        index  index.html;
    }
}

配置location的時候,按照規則,我訪問hello.test.com/aa
應該會訪問/data1/htdocs/hello.test.com/index.html
然而實際是404 not found
我查看error.log看到

2016/08/07 10:53:40 [error] 4686#0: *8 open() "/data1/htdocs/hello.test.com/aa" failed (2: No such file or directory), client: 192.168.31.198, server: hello.test.com, request: "GET /aa HTTP/1.1", host: "hello.test.com"

然而確是在訪問 hello.test.com/aa 這個目錄了,而我的目錄下沒有這個文件,這是什麼情況,求解

迷茫迷茫2732 天前675

全部回覆(1)我來回復

  • 怪我咯

    怪我咯2017-04-26 09:03:03

    首先,要設定存取 /aa 到 /data1/htdocs/hello.test.com/index.html ,你應該使用 alias 而不是 root。
    另外,配置子目錄應該閉合,不要使用 /aa ,應該使用 /aa/

    回覆
    0
  • 取消回覆