gpt4 book ai didi

nginx - 如果应用程序映射到子目录,如何在 Nginx + Flask 设置中加载静态文件

转载 作者:行者123 更新时间:2023-12-02 09:31:45 25 4
gpt4 key购买 nike

我有一个在域(例如 example.com)上运行的基本 html 站点,并且我想在子目录(例如:example.com/test)中运行 Flask 应用程序Flask 应用程序使用默认的 Flask 开发服务器在端口 5433 上运行。

我使用以下 nginx 配置来实现此目的

location /test {
rewrite /test(.*) $1 break;
proxy_pass http://localhost:5433;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static/{
alias /home/hrishi/www/example.com/test/app/static/;
}

我可以使用 example.com/test/url 访问该应用程序,但尽管有别名,静态文件仍无法加载(给出 404 错误)。

我该如何解决这个问题?

最佳答案

这是因为有一个额外的

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
expires max;

}

在服务器 block 内,我将其删除并通过

更改了静态目录的权限
chmod -R 664 /the/path/to/static/dir
chmod a+X /the/path/to/static/dir

它就像一个魅力

关于nginx - 如果应用程序映射到子目录,如何在 Nginx + Flask 设置中加载静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26909699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com