centos - nginx配置location的时候index不起作用?

查看:580
本文介绍了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 这个目录了,而我的目录下没有这个文件,这是什么情况,求解

解决方案

首先,要配置访问 /aa 到 /data1/htdocs/hello.test.com/index.html ,你应该使用 alias 而不是 root。
另外,配置子目录应该闭合,不要使用 /aa ,应该使用 /aa/

这篇关于centos - nginx配置location的时候index不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆