Install Ubuntu:

Install Ubuntu from the following link and update it using below commands :

apt update 
apt full-upgrade -y

Install NGINX:

Download latest version of Nginx from the following link :

dpkg -i nginx_1.12.0-1~xenial_amd64.deb
systemctl enable nginx.service
systemctl start nginx.service

replace this config with your /etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/;

events {
  worker_connections  1024;

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

  access_log  /var/log/nginx/access.log  main;

  sendfile             on;
  tcp_nopush           on;
  keepalive_timeout    65;
  gzip  on;
  server_tokens        off;
  add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
  add_header X-Content-Type-Options nosniff;
  add_header X-Frame-Options DENY;

  upstream my_django_app {
    server unix:///run/uwsgi.socket;
  server {
    listen       80 default_server deferred;
    server_name  _;

    charset utf-8;
    access_log  /var/log/nginx/log/host.access.log  main;

    location /media  {
      alias /var/www/site/media;

    location /static {
      alias /var/www/site/static;

    location / {
      uwsgi_pass  my_django_app;
      include     uwsgi_params;


Now, enter "nginx -t" command to validate your nginx.conf file.

nginx -t
systemctl restart nginx.service

Install UWSGI:

OK, Nginx is ready, Let’s go to setup Uwsgi:

apt install python3-dev python3-pip
pip install uwsgi

Install SystemD:

I’d like to use emperor feature of Uwsgi. More importantly, I’d like to use SystemD to keep Uwsgi service up and running. open /etc/systemd/system/uwsgi.service file and write :

Description=uWSGI service unit

ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -INT $MAINPID


Enable and start the aforementioned service using the following commands :

systemctl enable uwsgi.service
systemctl start uwsgi.service
mkdir /etc/uwsgi

I’d highly recommend to config your sample website by replacing the contents of /etc/uwsgi/site.ini file as follows :

module = wsgi
chmod-socket = 666
vacuum = true
die-on-term = true
chdir = /var/www/site/
module =  site.wsgi
master = true
processes = 10
socket = /run/uwsgi.socket

By any chance, if you wanted to restart your Uwsgi service, just enter :

systemctl restart uwsgi.service

Install PostgreSQL:

Mission accomplished! :) Our Nginx is ready and is listening on port 80 and passing requests to “/run/uwsgi.socket” socket proxy.
On the other side, Systemd keeps the Uwsgi up and running while Uwsgi uses “/etc/uwsgi/site.ini” config file.
Finally, if you want to use Postgresql as your back-end database, you can install and configure it with the following commands :

apt -y install postgresql postgresql-contrib postgresql-server-dev-all

now connect to psql and create new database with owner:

su - postgres psql template1
CREATE USER site_user WITH PASSWORD 'SitePassword';
GRANT all ON DATABASE site_db TO site_user;