Running Python Eve Rest API in production

It is time to move my Python Eve Api to a production environment. There are several ways to do this, and the most common are:

  • Error Logging
  • Automatic update
  • Multiple processes (if possible)

The best solution I found is to have a nginx server as an external server. With python python running on uWSGI middleware .

Problem: I have a custom __main__one that is not being called by uwsgi.

Does anyone have this configuration or other suggestion? As soon as this works, I will share the current configuration.

thank.

Solution (update):

Following the suggestion below, I moved the Eve () method to init .py and ran the application using sperate wsgi.py.

Folder structure :

webservice / init.py web service / modules / ... settings.py wsgi.py

Where init.py contains

app = Eve(auth=globalauth.TokenAuth)
Bootstrap(app)
app.config['X_DOMAINS'] = '*'
...

and wsgi.py contains

from webservice import app
if __name__ == "__main__":
  app.run()

wsgi.ini

[uwsgi]
chdir=/var/www/api/prod
module=wsgi:app
socket=/tmp/api.sock
processes=1
master=True
pidfile=/tmp/api.v1.pid
max-requests=5000
daemonize=/var/www/api/logs/prod.api.log
logto=/var/www/api/logs/uwsgi.log

nginx.conf

location = /v1 { rewrite ^ /v1/; }
    location /v1 { try_files $uri @apiWSGIv1; }
    location @apiWSGIv1 {
              include uwsgi_params;
              uwsgi_modifier1 30;
              uwsgi_pass unix:/tmp/digdisapi.sock;
    }

start command:

uwsgi --ini uwsgi.ini
+4
source share
1 answer

WSGI containers expect a function to be started / function; they do not execute your "master" record. With run: Eve, you ask uWSGI to execute (with each request) the "Eve" function in the "run" module (which is obviously wrong)

Move

app = Eve(auth=globalauth.TokenAuth)

__main__ uWSGI, "", "run"

module = run:app
+4

Source: https://habr.com/ru/post/1532967/


All Articles