Skip to content

GeoHealthCheck installation with nginx uwsgi

Cezary Statkiewicz edited this page Sep 7, 2017 · 1 revision

GeoHealthCheck production deployment

Prerequirements

  • nginx
  • uwsgin
  • postgresql

DB

psql < "create user ghc with password 'ghc'; create database ghc owner ghc;"

UWSGI config in /etc/uwsgi/apps-enabled/geohealthcheck.ini

[uwsgi]
uid = geosolutions
gid = www-data
chdir = /home/geosolutions/work/repo/GeoHealthCheck/
module = instance.wsgi:application
plugins = python
virtualenv = /home/geosolutions/.virtualenvs/geonode/
processes = 3
threads = 2
enable-threads = true
master = true
autoload = false
max-requests=50
buffer-size = 524288
touch-reload = /home/geosolutions/work/repo/GeoHealthCheck/instance/wsgi.py

Nginx config

Add following elements to site's config:


upstream ghc {
       server unix://run/uwsgi/app/geohealthcheck/socket;
}

server {
        ...
       location @ghc {
               etag off;
               uwsgi_pass  ghc;
               include     uwsgi_params;
               uwsgi_read_timeout 300s;
               #wsgi_param PATH_INFO $uws;
               uwsgi_param SCRIPT_NAME /ghc;
       }


       location /ghc {
               root /home/geosolutions/work/repo/GeoHealthCheck/instance/data/;
               try_files $uri @ghc;
       }
    ...
}

GHC setup

  • Enter venv

workon geonode; cd ~/work/repo

  • clone repo, checkout branch (if needed)

git clone git@github.com:geopython/GeoHealthCheck.git; cd GeoHealthCheck

  • run setup

paver setup

  • add instance/__init__.py

touch instance/init.py

  • edit instance/config_site.py
# things to change:

# Replace None with 'your secret key string' in quotes
# or generate one with paver create_secret_key
SECRET_KEY = '.....'

GHC_ADMIN_EMAIL = 'your email'
GHC_NOTIFICATIONS_EMAIL = ['your email too']
GHC_SITE_TITLE = 'GeoHealthCheck Demonstration'
GHC_SITE_URL = 'http://site/geohealtcheck/'
  • add instance/wsgi.py
#!/usr/bin/env python

import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

class ReverseProxied(object):
  def __init__(self, app):
      self.app = app

  def __call__(self, environ, start_response):
      script_name = environ.get('SCRIPT_NAME')
      if script_name:
          environ['SCRIPT_NAME'] = script_name
          path_info = environ.get('PATH_INFO')
          if path_info and path_info.startswith(script_name):
              environ['PATH_INFO'] = path_info[len(script_name):]

      scheme = environ.get('HTTP_SCHEME', '')
      if scheme:
          environ['wsgi.url_scheme'] = scheme
      server = environ.get('HTTP_X_FORWARDED_SERVER', '')
      if server:
          environ['HTTP_HOST'] = server
      return self.app(environ, start_response)


from GeoHealthCheck.app import APP

application = ReverseProxied(APP)
  • edit jobs.cron and add them to crontab

cat jobs.cron

@hourly /home/geosolutions/.virtualenvs/geonode/bin/python /home/geosolutions/work/repo/GeoHealthCheck/GeoHealthCheck/models.py run
@daily /home/geosolutions/.virtualenvs/geonode/bin/python /home/geosolutions/work/repo/GeoHealthCheck/GeoHealthCheck/models.py flush

crontab < jobs.cron

  • restart uwsgi and nginx

    sudo service uwsgi restart; sudo service nginx restart

Clone this wiki locally