Coder Social home page Coder Social logo

run under uwsgi? about flask-appbuilder HOT 10 CLOSED

dpgaspar avatar dpgaspar commented on May 22, 2024 1
run under uwsgi?

from flask-appbuilder.

Comments (10)

dpgaspar avatar dpgaspar commented on May 22, 2024

On pythonAnywhere i use it like this, you don't actually use run.py on a web server, this is just for development.

import sys

# add your project directory to the sys.path
project_home = u'/home/flaskappbuilder/Flask-AppBuilder-Site'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

activate_this = '/home/flaskappbuilder/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

# import flask app but need to call it "application" for WSGI to work
from app import app as application

from flask-appbuilder.

dpgaspar avatar dpgaspar commented on May 22, 2024

This should be your wsgi.py file. Please check if this works, then report back.

Thank You.

from flask-appbuilder.

gitrad avatar gitrad commented on May 22, 2024

I followed this tutorial:
(https://www.digitalocean.com/community/articles/how-to-deploy-flask-web-applications-using-uwsgi-behind-nginx-on-centos-6-4)
step by step for my fab and it worked fine except for static files ( icons, css, ...) this is my nginx.conf:


worker_processes 1;

events {

worker_connections 1024;

}

http {

sendfile on;

gzip              on;
gzip_http_version 1.0;
gzip_proxied      any;
gzip_min_length   500;
gzip_disable      "MSIE [1-6]\.";
gzip_types        text/plain text/xml text/css
                  text/comma-separated-values
                  text/javascript
                  application/x-javascript
                  application/atom+xml;

# Configuration containing list of application servers
upstream uwsgicluster {

    server 127.0.0.1:8080;
    # server 127.0.0.1:8081;
    # ..
    # .

}

# Configuration for Nginx
server {

    # Running port
    listen 80;

    # Settings to by-pass for static files 
    location ^~ /static/  {

        # Example:
        # root /full/path/to/application/static/file/dir;
        root /app/static/;

    }

    # Serve a static file (ex. favico) outside static dir.
    location = /favico.ico  {

        root /app/favico.ico;

    }

    # Proxying connections to application servers
    location / {

        include            uwsgi_params;
        uwsgi_pass         uwsgicluster;

        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;

    }
}

}


pasted from that tutorial. how to serve static files? thanks.

from flask-appbuilder.

dpgaspar avatar dpgaspar commented on May 22, 2024

I have configured it in a different way (no need to change nginx.conf):

First change run.py to this

from app import app

if __name__ == '__main__':
        app.run(host='0.0.0.0')

1 - /etc/nginx/sites-available/mysite

server {
    listen 0.0.0.0:8090;
    server_name _;

location / { try_files $uri @yourapplication; }
location @yourapplication {
      include uwsgi_params;
      uwsgi_pass unix:/tmp/mysite.sock;
    }
}

2 - exec*

ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysite

3 - /etc/uwsgi/apps-available/myapp.ini*

[uwsgi]
vhost = true
socket = /tmp/mysite.sock
chmod-socket = 666
venv = /home/dpgaspar/workspace/env
chdir = /home/dpgaspar/workspace/quickhowto
module = run
callable = app

4 - exec

sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysite

5 - exec

sudo touch /tmp/mysite.sock
sudo chown www-data:www-data /tmp/mysite.sock
sudo chmod 666 /tmp/mysite.sock

6 - Restart and watch the logs

sudo service nginx restart
sudo service uwsgi restart
sudo tail -f /var/log/uwsgi/app/myapp.log &
sudo tail -f /var/log/nginx/error.log

from flask-appbuilder.

dpgaspar avatar dpgaspar commented on May 22, 2024

Remember: on the above config, change myapp.ini keys chdir and venv to your F.A.B. app venv and directory.

Hope this helps.

from flask-appbuilder.

gitrad avatar gitrad commented on May 22, 2024

I did so ( in FreeBSD 10 ):
1.create a file WSGI.py next to run.py and inside:


from app import app
if name == "main":
app.run(host='127.0.0.1', port='8000')


2.and in nginx.conf:


location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}


3.and finaly issued ( insilde activated virtualenv ):
-> uwsgi --socket 127.0.0.1:8000 -w WSGI:app
then it worked as expected ( without extra conf ).

from flask-appbuilder.

GregSilverman avatar GregSilverman commented on May 22, 2024

Hi there! I am fighting with this configuration on a Mac and unable to get it working. Any chance of sharing a working recipe? I have other Flask apps working just fine in uWSGI/Nginx, but this one is presenting itself to be quite a challenge. Thanks in advance!

from flask-appbuilder.

GregSilverman avatar GregSilverman commented on May 22, 2024

I guess I should be more clear. I am able to get my app working on port 8080, but not on port 80. Other Flask apps run just fine on port 80.

from flask-appbuilder.

GregSilverman avatar GregSilverman commented on May 22, 2024

If you want, I can open a new issue.

from flask-appbuilder.

GregSilverman avatar GregSilverman commented on May 22, 2024

Never mind, I ran the following uwsgi command in my flask-appbuilder directory: uwsgi -s /tmp/uwsgi.sock -H ./venv/ --chmod-socket=666 --wsgi-file myproject/wsgi.py and all is working on port 80.

from flask-appbuilder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.