我想使用 Nginx 为前端 angular 2 应用程序提供服务。我使用 Gunicorn 作为 Nginx 和 Flask 之间的媒介。我想将此 Web 应用程序部署到生产环境。这样做的正确应用程序结构应该是什么?另外,nginx 服务器 block 配置是什么?我托管在基于 digital ocean Linux 的小滴(Ubuntu 16.04)上。我引用了以下链接,但他们似乎也在使用 Flask 来服务前端。
https://www.digitalocean.com/community/tutorials/how-to-structure-large-flask-applications
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-16-04
最佳答案
这是一个示例 Nginx 配置文件。我确信这不是最好的方法,但它让我测试了我的应用程序。
server {
listen 80;
server_name localhost;
# Your angular app
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
# Static files
location /static {
alias /usr/share/nginx/flask/static;
}
# Gunicorn
location /api {
proxy_pass http://localhost:4000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
注意事项
dist
文件夹。让 nginx 指向它。给定为 /usr/share/nginx/html
在配置中。这个link帮助我更好地了解 Angular CLI。 gunicorn -b 127.0.0.1:4000 app:app
.转至 /api
. 希望这至少能让你继续前进。
关于ubuntu - 如何与 Flask 后端 api 一起构建 Angular 2 前端应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41327350/