Deploy SwampDragon with Nginx, Supervisor and Django

437 views Asked by At

I have deployed my application in Linode. But for testing SD I used a pc as server in my local network where I have running my application. I'd like to share my Nginx and Supervisor config if you could give me some advice if it is right or I've made a mistake.

I modified my hosts file to access with www.mydomain.com.

In my settings.py file I have:

# SWAMPDRAGON
SWAMP_DRAGON_CONNECTION = ('swampdragon_auth.socketconnection.HttpDataConnection', '/data')
DRAGON_URL = 'http://127.0.0.1:9999'

I took as example what I did for celery and reuse that to do something similar with SD: I created a command file: 'swampdragon_start'

#!bin/bash
NAME="swampdragon"
DJANGODIR=/opt/virtualenvs/myproject/pysrc/myproject/myproject

# Enable virtualenv

cd $DJANGODIR
source ../../../bin/activate
export C_FORCE_ROOT="true"

# Execute SD
exec python manage.py runsd 0.0.0.0:9999

Then I created a file for supervisor: 'swampdragon.conf'

[program:swampdragon]
command = /opt/virtualenvs/myproject/bin/swampdragon_start
user = root
stdout = /path/to/file.log
stderr = /path/to/file.log
autostart = true
autorestart = true

Finally, I made swampdragon_start executable, and add swampdragon to supervisor.

My Nginx config is as follow:

upstream swampdragon{
    server 127.0.0.1:9999;
}

proxy_next_upstream off;

server {
    listen 80;
    server_name www.mydomain.com;

    access_log /path/to/log
    error_log /path/to/log

    location /media/ {
        alias /path/to/media
    }

    location /static/ {
        alias /path/to/statics
    }

    location / {
        ...  # django config
    }
}

server {

    # this is taken from http://swampdragon.net/blog/deploying-swampdragon/
    listen 80;
    server_name sd.mydomain.com;

    # Websocket
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header Host $http_host;
        proxy_pass http://swampdragon;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

That's how I've made it work, but I think Nginx upstream is not working really. I am sure there's a better way to deploy SD, any suggestion?

Thanks for your time.

0

There are 0 answers