Web server

From imdb
Revision as of 10:52, 13 October 2015 by Bjo013 (talk | contribs) (Example: fossrate)
Jump to: navigation, search

We are using nginx as the web server and reverse proxy for our web pages and apps.

Setting up a new web page

nginx is configured by editing /etc/nginx/nginx.conf.

Serving a new static index.html file from /data_bck/public/html you would write

Setting up a python flask application

We are using uwsgi to serve standalone python flask web applications. (The uwsgi server can be used for web applications written in other languages than just python.)

To set up a new application, a .ini file is needed in /etc/uwsgi.d. This folder is followed by the uwsgi "emperor". The emperor is responsible for restarting and managing each uwsgi "vassal", which holds your application. There is a file /etc/uwsgi.d/flask.skel; this is a skeleton file that can be used instead writing your own. It does however assume some things about your application. It needs to be installed in /data_bck/public/PROJECT_NAME. The main file should be called PROJECT_NAME.py and it should contain a pyvenv called env. You then need to configure nginx to talk to the newly created uwsgi vassal.

Example: fossrate

Fossrate is located at /data_bck/public/fossrate and should have the url nelson.uib.no/fossrate.

Fossrate has a database file that needs to read an writeable by the uwsgi user.

cd /data_bck/public/fossrate
chown uwsgi:www-data scoreboard.db

Fossrate depends on the flask package. We need to create a virtual environment and install flask.

module load python
pyvenv env
pip install flask

If you are going to use the flask.skel package it is important that you call the environment env.

We then copy the flask.skel file to fossrate.ini

cp /etc/uwsgi.d/flask.skel /etc/uwsgi.d/fossrate.ini

This will open a unix socket at /run/uwsgi/fossrate.sock and give read/write permissions to the www-data group which it shares it the nginx user.

We then add the following entry to the /etc/nginx/nginx.conf file inside server {}.

location = /fossrate { rewrite ^ /fossrate/; }
location /fossrate { try_files $uri @fossrate; }
location @fossrate {
    include uwsgi_params;
    uwsgi_pass unix:///run/uwsgi/fossrate.sock;

To put the configuration into effect nginx need to be restarted. You can restart it by running the command

sudo systemctl restart nginx.service

uwsgi should not need to be restarted when changing the nginx config.