nginx 服务器上定向到 index.html 时出现奇怪的重定向问题

nginx 服务器上定向到 index.html 时出现奇怪的重定向问题

我正在尝试使用 nginx 部署单页应用程序,以下是配置。

 server {
    listen 24670 default_server;
    listen [::]:24670 default_server;
    server_name *******;

        root /home/gerry/client/dist;
        index index.html index.htm;

        location / {
           try_files $uri /index.html;
        }
}

每当我尝试访问该页面时,我都会收到 500 内部服务器错误,检查日志时,我会看到以下错误。

2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"
2017/10/15 18:20:17 [error] 8752#8752: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670"

我已经将权限和所有权设置为 www-data,但不确定还需要做什么才能提供 index.html 文件

答案1

根本问题是权限问题,请检查运行服务器的用户是否可以访问index.html(完整路径)。

重定向是由 try_files 指令引起的,添加 404 作为最后的尝试,即使出现错误也能停止它。

相关内容