>  Q&A  >  본문

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일 전676

모든 응답(1)나는 대답할 것이다

  • 怪我咯

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

    먼저 /aa에서 /data1/htdocs/hello.test.com/index.html로의 액세스를 구성하려면 루트 대신 별칭을 사용해야 합니다.
    또한 구성 하위 디렉터리를 닫아야 합니다. /aa를 사용하지 말고 /aa/를 사용하세요.

    회신하다
    0
  • 취소회신하다