Deploying a source install#

Since CKAN is written mainly in Flask and supports WSGI, CKAN can be used with a number of different web server and deployment configurations.

This guide explains how to deploy CKAN using uwsgi and proxied with nginx.

1. Create the WSGI script file#

sudo cp /usr/lib/ckan/default/src/ckan/wsgi.py /etc/ckan/default/

2. Create the WSGI Server#

Install uwsgi into a Python virtual environment and create the configuration file:

. /usr/lib/ckan/default/bin/activate
pip install uwsgi
sudo cp /usr/lib/ckan/default/src/ckan/ckan-uwsgi.ini /etc/ckan/default/

Edit the /etc/ckan/default/ckan-uwsgi.ini and replace the uid and pid with the owner of the virtual environment.

3. Modify the configuration file#

Important

(For depositar administrator) Please ignore this step and use the backed up production.ini.

Edit the production.ini file in a text editor, changing the [app:main] sections as follows:

## Site Settings

ckan.site_url = http://127.0.0.1

## XLoader Settings
## Refer to the CKAN database
ckanext.xloader.jobs_db.uri = postgresql://ckan_default:pass@localhost/ckan_default

4. Install Supervisor#

sudo apt-get install supervisor

5. Set the startup script for CKAN#

  1. Create the Supervisor configuration for CKAN:

    sudo vi /etc/supervisor/conf.d/ckan-uwsgi.conf
    
  2. In the vi editor, add the following contents:

    [program:ckan-uwsgi]
    
    command=/usr/lib/ckan/default/bin/uwsgi -i /etc/ckan/default/ckan-uwsgi.ini
    
    ; Start just a single worker. Increase this number if you have many or
    ; particularly long running background jobs.
    numprocs=1
    process_name=%(program_name)s-%(process_num)02d
    
    ; Log files - change this to point to the existing CKAN log files
    stdout_logfile=/etc/ckan/default/uwsgi.OUT
    stderr_logfile=/etc/ckan/default/uwsgi.ERR
    
    ; Make sure that the worker is started on system start and automatically
    ; restarted if it crashes unexpectedly.
    autostart=true
    autorestart=true
    
    ; Number of seconds the process has to run before it is considered to have
    ; started successfully.
    startsecs=10
    
    ; Need to wait for currently executing tasks to finish at shutdown.
    ; Increase this if you have very long running tasks.
    stopwaitsecs = 600
    
    ; Required for uWSGI as it does not obey SIGTERM.
    stopsignal=QUIT
    

6. Set the startup script for XLoader#

Note

This XLoader is a service that automatically uploads data to the DataStore from suitable files (like CSV or Excel files), whether uploaded to CKAN’s FileStore or externally linked.

sudo mkdir -p /var/log/ckan
sudo cp /usr/lib/ckan/default/src/ckan/ckan/config/supervisor-ckan-worker.conf /etc/supervisor/conf.d

7. Restart Supervisor#

sudo service supervisor restart

You can check the status via:

sudo supervisorctl status

You can restart the workers via:

sudo supervisorctl restart ckan-uwsgi:*
sudo supervisorctl restart ckan-worker:*

8. Install and setup nginx#

  1. Install nginx:

    sudo apt-get install nginx
    

b. Create your site’s Nginx config file at /etc/nginx/sites-available/ckan, with the following contents:

proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=cache:30m max_size=250m;
proxy_temp_path /tmp/nginx_proxy 1 2;

server {
    client_max_body_size 100M;
    location / {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_cache cache;
        proxy_cache_bypass $cookie_auth_tkt;
        proxy_no_cache $cookie_auth_tkt;
        proxy_cache_valid 30m;
        proxy_cache_key $host$scheme$proxy_host$request_uri;
        # In emergency comment out line to force caching
        # proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
    }
}
  1. To prevent conflicts, disable your default nginx sites. Finally, enable your CKAN site in nginx:

    sudo rm /etc/nginx/sites-enabled/default
    sudo ln -s /etc/nginx/sites-available/ckan /etc/nginx/sites-enabled/ckan
    
  2. Restart nginx:

    sudo service nginx restart
    

9. Test the site#

You should now be able to visit your server (at http://127.0.0.1) in a web browser and see your new CKAN instance.