【问题标题】:Running gunicorn & flask with pm2 doesn't load proper css使用 pm2 运行 gunicorn 和烧瓶无法正确加载 css
【发布时间】:2018-12-08 19:18:42
【问题描述】:

如果我使用 pm2 运行我的烧瓶应用程序,我会在不考虑 css 和图像等的情况下渲染一个网站。

我的烧瓶应用如下所示:

from flask import Flask, render_template
app = Flask(__name__)
app.secret_key='fiujhdfjksdjkfbskfbd'

@app.route("/")
def index_page():
    return render_template('index.html')

if __name__ == "__main__":
    app.run(host='0.0.0.0', port='8080')

进入/etc/nginx/sites-available/default我写了以下内容:

server {  
    listen 80;
    listen [::]:80;
    server_name www.mydomain.com mydomain.com;
    location / {
        proxy_pass http://0.0.0.0:8000;                                                                                                                                
    }
}

在开始文件中我写了这个:

source venv/bin/activate
gunicorn -w 10 flask_app:app

然后我以pm2 start start_script 开头

有人知道怎么回事吗?

【问题讨论】:

标签: python nginx flask gunicorn pm2


【解决方案1】:

您错过了我添加的 2 行。在nginx配置中,你还需要指向flask中包含css和java脚本的静态文件。

server {  
    listen 80;
    listen [::]:80;
    server_name www.mydomain.com mydomain.com;
    location / static {
        alias /home/YOUR_USER/YOUR_PROJECT/static;
    }
    location / {
        proxy_pass http://0.0.0.0:8000;                                                                                                                                
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 2014-04-07
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    相关资源
    最近更新 更多