【问题标题】:Nginx try_files points to wrong folderNginx try_files 指向错误的文件夹
【发布时间】:2020-05-10 04:31:59
【问题描述】:

我正在使用 nginx docker 托管一个 vue 历史站点,并且 nginx 配置如下

server {
        listen 80;
        location / {
                root   /var/www/dist/;
                index  index.html index.htm;
                try_files $uri $uri/ index.html;
        }

}

我可以访问“http://the.ip.of.server”。但是,当我尝试访问“http://the.ip.of.server/search”时,它显示以下错误。它试图打开“/etc/nginx/htmlindex.html”而不是“/var/www/dist/index.html”,这是没有意义的。

2020/05/10 04:24:01 [error] 7#7: *2 open() "/etc/nginx/htmlindex.html" failed (2: No such file or directory), 
client: xx.xx.xx.xx, server: , request: "GET /search HTTP/1.1", host: "the.ip.of.server"

我不知道“/etc/nginx/htmlindex.html”来自哪里。配置应该是正确的,因为我可以访问/

【问题讨论】:

  • 你能跑nginx -t吗?

标签: vue.js nginx


【解决方案1】:

您应该将root 元素放在location 块之外。

server {
   listen 80;
   root /var/www/dist;
   index index.html index.htm
   location / {
      try_files $uri $uri/ =404;
   }
}

更改配置后记得重启nginx 实例(如果使用 docker force build image)。

【讨论】:

    猜你喜欢
    • 2012-05-28
    • 2019-02-07
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2013-12-23
    • 2018-12-19
    • 1970-01-01
    • 2018-03-01
    相关资源
    最近更新 更多