访问子目录下的html时找不到404 404

时间:2014-10-31 11:54:37

标签: nginx

我无法访问tw文件夹

下的网页

例如:about.html

我会收到此错误404 Not Found

但我可以访问index.html页面

Nginx conf

server{
    server_name great.com;
    root /www/gp;
    expires off;
    try_files $uri/index.html /dev/null =404;

    location ~* \.(js|jpg|png|css)$ {
        root /www/gp;
        expires 30d;
    }

    location /tw/ {
        autoindex on;
        root /www/gp/tw;
    }

}

文件夹结构

.
├── index.html
└── tw
    ├── about.html
    ├── brand01.html
    ├── brand.html
    ├── contact.html
    ├── css
    ├── faq01.html
    ├── faq02.html
    ├── images
    ├── js
    └── news.html

nginx日志中的错误日志

2014/10/31 12:00:15 [error] 12047#0: *6 open() "/www/gp/tw/tw/images/waves.gif" failed (2: No such file or directory), client: 118.163.149.126, server: great-compassion.com, request: "GET /
tw/images/waves.gif HTTP/1.1", host: "www.great-compassion.com", referrer: "http://www.great-compassion.com/tw/css/banner.css"
2014/10/31 12:00:18 [error] 12047#0: *5 open() "/www/gp/tw/tw/brand.html" failed (2: No such file or directory), client: 118.163.149.126, server: great-compassion.com, request: "GET /tw/bra
nd.html HTTP/1.1", host: "www.great-compassion.com", referrer: "http://www.great-compassion.com/"

1 个答案:

答案 0 :(得分:1)

重复的根

请勿在两个位置重新定义root。正如您在错误日志中看到的那样,/www/gp/tw/tw/brand.html出现两次。也就是说,位置中的路径是包容性的,就像the documentation states about root一样。

location /i/ {
  root /data/w3;
}

将发送/data/w3/i/top.gif文件以响应/i/top.gif请求。