user2399453
user2399453

Reputation: 3081

Running a Flask app on nginx

I don't know exactly what I am doing but I am experimenting with running Flask on nginx. I am boiling it down to the simple bit of code below. First I have a test app in Flask like this:

 from flask import Flask, render_template

 app = Flask(__name__, static_folder='client', template_folder='client/html')

 def show_home_page():
    return render_template("home.html")

 @app.route('/')
 def server():
    return show_home_page()

 if __name__ == '__main__':
    app.run(threaded=True)

If I run python app.py I can go to http://localhost:5000 and see the "Hello World". Next I read that I need to run uwsgi but its not clear what params I need to pass to it. I tried different things like:

 uwsgi -s /tmp/app.sock --manage-script-name --mount ./=app:app

I also noted that I need to set my nginx conf file to match, but I am stuck on that as well (I just get a welcome from nginx on port 5000) and it doesnt seem to link with my Flask app. I googled around a bit but nothing has clicked yet.

server {
    listen       5000;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

Upvotes: 1

Views: 3119

Answers (1)

illusionx
illusionx

Reputation: 3845

You can use refer this for Flask with Nginx and uWSGI: Python flask with Nginx and uWSGI

Upvotes: 1

Related Questions