【发布时间】:2019-05-27 12:03:33
【问题描述】:
我有 Nginx 设置基于 Flask 的后端运行在端口 8080 上,配置如下
server {
listen 8080 default_server;
listen [::]:8080;
root /var/www/html;
server_name _;
location /static {
alias /var/www/html/static/;
}
location / {
try_files $uri @wsgi;
}
location @wsgi {
proxy_pass http://unix:/tmp/gunicorn.sock;
include proxy_params;
}
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
}
我还设置了一个使用 gunicorn 运行烧瓶应用程序的 systemd 服务:gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 start_backend:web_app
现在以上内容适用于端口 8080 上的 Python Flask 后端,我还想在默认端口 80 上添加 Vue 应用程序。
更新
server {
listen 80 default_server;
listen [::]:80;
root /var/www/html/dist;
server_name _;
location /static {
alias /var/www/html/dist/static/;
}
location / {
root /var/www/html/dist;
try_files $uri $uri/ /index.html;
}
location /api {
root /var/www/html;
try_files $uri @wsgi;
}
location @wsgi {
proxy_pass http://unix:/tmp/gunicorn.sock;
include proxy_params;
}
【问题讨论】: