Django + Nginx + uWSGI + Supervisor with SSL

In Lifestyle on March 17th, 2016

Following is Nginx configuration. This will redirect all http request to https

upstream uwsgi {
    server unix:///tmp/wb/uwsgi.sock;
}

server {
	listen 80 default_server;
	server_name _;
	return	302 https://$host$request_uri;
}

server {
	listen 443 ssl;

	root /path/to/project/root;
	index index.html index.htm;

        # to support any
	# server_name _;
        server_name mydomain.com    

	ssl_certificate /path/to/ssl/ceftificate.crt;
	ssl_certificate_key /path/to/signing_key.key;
	ssl_protocols	TLSv1 TLSv1.1 TLSv1.2;


	location / {
		uwsgi_pass uwsgi;
		include /var/www/whosbetter/uwsgi_params;
                uwsgi_param      CUSTOM_VAR Vallue
	}

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

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

Supervisor:

Install:

apt-get install supervisor

Add configuration:

vi /etc/supervisor/conf.d/uwsgi.conf

Add following content

[program:uwsgi]
user = uwsgi
command=/path/to/uwsgi --ini /path/to/uwsgi.ini
autostart=true
autorestart=true
stderr_logfile = /var//log/uwsgi_err.log
stdout_logfile = /var/log/uwsgi_out.log
stopsignal=INT

Reload Supervisor config:

supervisorctl reread

Enact the changes:

supervisorctl update