首页 > 解决方案 > 我的 Nginx 服务器静态内容显示 403 禁止错误。为什么?

问题描述

我用 gunicorn 部署了我的烧瓶应用程序,并让 nginx 提供静态内容。.conf 文件是这样的

server {
        listen  80;
        listen  [::]:80;

        server_name     lab01.net;

        location /static {
                alias   /home/lab01/blog/flaskblog/static;
                autoindex       on;
        }

        location / {
                proxy_pass      http://localhost:8000;
                proxy_redirect  off;
        }


}

我认为配置是正确的,但是当我在浏览器http://lab01.net/static中访问静态文件时,发现 403 禁止错误。

然后我检查了 nginx 日志文件,日志文件一直说

2021/09/19 19:45:18 [error] 86998#0: *7 "/home/lab01/blog/flaskblog/static/index.html" is forbidden (13: Permission denied), client: 192.168.89.1, server: lab01.net, request: "GET /static/ HTTP/1.1", host: "lab01.net"

在日志文件中,它说/home/lab01/blog/flaskblog/static/index.html是被禁止的。为什么老是这样说?为什么服务器访问 index.html?在静态文件夹中只有图像和 css 文件。它应该访问这些文件而不是 index.html 吗???

注意:当我第一次在服务器上部署时,静态内容正确显示并且没有错误。在我将所有代码库切换到另一台服务器并重新配置 nginx 之后。我遇到这个错误。所有的防火墙和 SeLinux fcontext 和 boolean 也都配置好了。

标签: nginxflask

解决方案


推荐阅读