title: Running Python Eve Rest API in Production
body: <p>It is no time to move my Python Eve Api into a production environment. There are several ways to do this and the most common requirements are:</p>
  
  <ul>
  <li>Error Logging</li>
  <li>Automatic Respawn</li>
  <li>Multiple Processes (if possible)</li>
  </ul>
  
  <p>The best solution I found is to have a nginx server as frontend server. 
  With <strong>python eve running on the uWSGI middleware</strong>. </p>
  
  <p><strong>The problem: I have a custom <code>__main__</code> which is not called by uwsgi.</strong></p>
  
  <p>Does anyone have this configuration running or another proposal? As soon as it works, I will share a running configuration.</p>
  
  <p>thank you.</p>
  
  <h2><strong>Solution (Update):</strong></h2>
  
  <p>Based on the proposial below I moved the Eve() Method to the <strong>init</strong>.py and run the app with a sperate wsgi.py.</p>
  
  <p><strong>Folder structure</strong>:</p>
  
  <p>webservice/ init.py 
  webservice/modules/...
  settings.py
  wsgi.py</p>
  
  <p>Where   init.py contains</p>
  
  <pre><code>app = Eve(auth=globalauth.TokenAuth)
  Bootstrap(app)
  app.config['X_DOMAINS'] = '*'
  ...
  </code></pre>
  
  <p>and wsgi.py contains</p>
  
  <pre><code>from webservice import app
  if __name__ == "__main__":
    app.run()
  </code></pre>
  
  <p>wsgi.ini</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>nginx.conf</p>
  
  <pre><code>location = /v1 { rewrite ^ /v1/; }
      location /v1 { try_files $uri @apiWSGIv1; }
      location @apiWSGIv1 {
                include uwsgi_params;
                uwsgi_modifier1 30;
                uwsgi_pass unix:/tmp/digdisapi.sock;
      }
  </code></pre>
  
  <p>start command:</p>
  
  <pre><code>uwsgi --ini uwsgi.ini
  </code></pre>