nginx:location = / {}错误

时间:2017-08-24 02:53:37

标签: nginx nginx-location

我的nginx vhost配置内容:

server {
    listen 80;
    server_name t.xianzhi.xxx.domain;
    access_log /data/log/nginx/t.xianzhi.xxx.domain_access.log main;

    location ~ /\. {deny  all;}

    proxy_set_header    X-Real-IP       $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    Host            $host;

    location = / {
        root /data/web/static/html;
        index index.html;
    }

    location / {
        proxy_pass          http://127.0.0.1:9000;
    }

    location = /favicon.ico {
        access_log off;
        root /data/web/static/;
    }

    location = /apple-app-site-association {
        add_header Content-Type "text/html; charset=utf-8";
        root /data/web/show/public/wap/;
    }

    location ~ \.(css|js|png|jpg|woff|ttf)$ {
        root /data/web/static;
        expires 10d;
    }

}

作为配置,我想将路径/服务到/data/web/static/html/index.html,并将其他路径服务到proxy_pass。

事实是路径/未找到404而其他路径成功。

日志是:

24/Aug/2017:10:49:43 +0800  10.5.17.37  t.xianzhi.xxx.domain    -   curl/7.51.0 -   request:GET / HTTP/1.1  bbs:233status:404   upad:127.0.0.1:9000 rspt:0.017  rqtt:0.017  request_body:-

因此,/将传递给代理。

一些信息:

nginx版本:nginx/1.10.1

那么,如何修复呢?

1 个答案:

答案 0 :(得分:1)

问题在于您的= /位置阻止。如果您考虑

部分
location = / {
    root /data/web/static/html;
    index index.html;
}

您指定了root和index.html,但您没有任何服务器。所以你应该把它改成

location = / {
    root /data/web/static/html;
    index index.html;
    try_files /index.html =404;
}

location = / {
    root /data/web/static/html;
    try_files /index.html =404;
}