nginx - 带有 web uwsgi 和 nginx 的烧瓶无法运行 index.html
问题描述
我在烧瓶中很新,尝试运行一个后端作为烧瓶的 Web 应用程序。我的项目文件夹结构是
~myproject/
~myproject/app (flask api)
~myproject/web (index.html)
使用 uwsgi 和 nginx 运行
uwsgi.ini
[uwsgi]
vhost = true
socket = /tmp/flask.sock
venv = /flask_app/.env
chdir = /flask_app/app
module = app
callable = app
nginx.conf
upstream flask_server {
ip_hash;
server 0.0.0.0;
}
server {
listen 80;
server_tokens off;
server_name _;
root /flask_app/web;
index index.html index.htm index.nginx-debian.html;
charset utf-8;
client_max_body_size 75M;
location / {
#try_files $uri $uri/ =404;
include uwsgi_params;
uwsgi_pass unix:/tmp/flask.sock;
}
#location /static {
# alias /flask_app/static;
#}
location /flask/ {
proxy_redirect off;
proxy_pass http://flask_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
但是 index.html 没有加载,它只允许 api url(如:127.0.0.1/login)?
解决方案
该指令告诉 Nginx 将与该位置块匹配的所有内容发送到上游服务器uwsgi_pass unix:/tmp/flask.sock
如果您只想提供 index.html 并将其他所有内容传递给上游,那么您可以像这样更改它:
location / {
try_files $uri/index.html @upstream;
}
location @upstream {
include uwsgi_params;
uwsgi_pass unix:/tmp/flask.sock;
}
推荐阅读
- java - 如何在不丢失 jlabel 中的增量值的情况下从一个 jframe 跳转到另一个
- java - 使用 Firebase 查询获取 NullPointerException 和应用程序崩溃
- azure - 登录到 Azure Sql
- c - 如何与 SoftFloat 库链接?
- spring-boot - 使用spring-boot在多个数据库之间进行数据迁移
- react-native - react-native 数字类型更改 returnKeyType
- spring - 使用 JdbcTemplate 的单个实例
- javascript - 注入到 body 元素的全浏览器屏幕 DIV
- android-fragments - Kotline:Recyclerview 和 Fragment 错误 E/RecyclerView:未连接适配器;跳过布局
- typescript - 来自打字稿的摩卡测试调试问题