Commit cd8fd44e authored by Romain Loth's avatar Romain Loth

finished wsgi mounting of the app (finally using gunicorn instead of uwsgi)

parent 6238dd47
......@@ -9,20 +9,68 @@ This folder contains nov 2016 registration form server
- the registration credentials are transmitted to a doors prototype
- the answers are POSTed back to server that writes new users in a local DB
More info in `docs/` directory
More info in `doc/` directory
-------
### Setting up the server on an nginx server
#### Running in dev
First we need to run the app
```
# install prerequisites
> sudo apt install python3
> sudo apt install python3-virtualenv
# start a virtualenv
> virtualenv --python=/usr/bin/python3 setup/regcomex_venv
> source setup/regcomex_venv/bin/activate
# additional requirements
(regcomex_venv) > pip3 install -r setup/requirements.txt
# run the app ----------------------------------------------------------
(regcomex_venv) > gunicorn -b 127.0.0.1:9090 server_comex_registration:app
# ----------------------------------------------------------
```
# in a virtualenv or a dedicated VM
pip3 install uwsgi flask
The form server is now accessible locally on `127.0.0.1:9090/regcomex`
(the default ROUTE_PREFIX is /regcomex, but TODO can be changed in config file)
#### Running in prod
Secondly we ask nginx to reverse-proxy our app
This is a minimal conf (cf [detailed doc](https://github.com/moma/regcomex/blob/master/doc/nginx_conf.md) for real-life conf)
```
# nginx exemple
server {
listen 80;
location /$ROUTE_PREFIX {
proxy_pass http://127.0.0.1:9090;
}
}
```
-------
### Setting up the doors connection
TODO config file for the doors api routes
-------
### Connecting the data to *communityexplorer.org*
Currently the data is collected in `data/registered.db`
The communityexplorer.org app is using a separate DB from legacy wiki csv
(cf [detailed doc](https://github.com/moma/regcomex/blob/master/doc/nginx_conf.md) for real-life conf)
**TODO:** connect the two
-------
(c) 2016 ISCPIF-CNRS
**contact** romain.loth@iscpif.fr
(c) 2016 ISCPIF-CNRS
### 1) Install nginx
```
sudo service apache2 stop
sudo apt install nginx-full # contains uwsgi http module
# check the status
systemctl status nginx.service # or sudo service nginx status
```
### 2) Add regcomex to nginx conf
Create the conf files for regcomex
```
cd /etc/nginx/sites-available
sudo nano regcomex.conf
```
Exemple content to add in `/etc/nginx/sites-available/regcomex.conf`
```
server {
# your normal server conf here
#listen 80;
#listen [::]:80;
#root /var/www ;
location /regcomex {
proxy_pass http://127.0.0.1:9090; # gunicorn will be serving here
proxy_redirect off;
# useful to keep track of original IP before reverse-proxy
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;
# get the logs in a custom place
access_log /home/romain/comex/regcomex/logs/nginx/access.log;
error_log /home/romain/comex/regcomex/logs/nginx/error.log;
}
# faster static serving
location /static {
alias /home/romain/comex/regcomex/static/;
autoindex on;
}
}
```
Finally enable the conf
```
cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/regcomex.conf
```
......@@ -62,12 +62,14 @@ COLS = [ ("doors_uid", True, 36),
# ============= views =============
# ------------------------------------------------------------------
# /!\ All routes will be prefixed by comexsomething/reg in prod /!\
# ------------------------------------------------------------------
# -----------------------------------------------------------------------
# /!\ Routes are not prefixed by nginx in prod so we do it ourselves /!\
# -----------------------------------------------------------------------
# prefix must match what nginx conf expects
ROUTE_PREFIX = "/regcomex"
@app.route("/", methods=['GET','POST'])
@app.route(ROUTE_PREFIX+"/", methods=['GET','POST'])
def one_big_form():
if request.method == 'GET':
return render_template("base_form.html")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment