centos - nginx設定location的時候index不起作用?
迷茫
迷茫 2017-04-26 09:01:03
0
1
681

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 這個目錄了,而我的目錄下沒有這個文件,這是什麼情況,求解

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(1)
刘奇

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

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!