具有Web uwsgi和nginx的烧瓶无法运行index.html

时间:2018-07-04 15:55:28

标签: nginx flask uwsgi

我对Flask非常陌生,请尝试以后端作为Flask运行Web应用程序。我的项目文件夹结构是
〜myproject /
〜myproject / app(烧瓶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)吗?

1 个答案:

答案 0 :(得分:0)

该指令告诉Nginx只是将与该位置块匹配的所有内容发送到上游服务器 location / { try_files $uri/index.html @upstream; } location @upstream { include uwsgi_params; uwsgi_pass unix:/tmp/flask.sock; }

如果您只想提供index.html并将其他内容传递给上游,则可以这样更改:

"main": "src/index.js"