3

If I run my flask app with pm2, I get rendered a website without any consideration of css and images etc.

My flask app looks like this:

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')

Into /etc/nginx/sites-available/default I wrote the following:

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

And into the start file I wrote this:

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

And then I start it with pm2 start start_script

Does anybody know what is wrong?

sunwarr10r
  • 4,420
  • 8
  • 54
  • 109

1 Answers1

1

You were missing the 2 lines which I have added. In the nginx configuration, you also need to point to static files in flask which contain css and java script.

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;                                                                                                                                
    }
}