Install Ubuntu:

Install Ubuntu from the following link and update it using below commands :
http://releases.ubuntu.com/16.04/ubuntu-16.04.2-server-amd64.iso

apt update 
apt full-upgrade -y

Install NGINX:

Download latest version of Nginx from the following link :
http://nginx.org/packages/ubuntu/pool/nginx/n/nginx/

wget http://nginx.org/packages/ubuntu/pool/nginx/n/nginx/nginx_1.12.0-1~xenial_amd64.deb
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/nginx.pid;

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  _;
    server_name  site.ir;

    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 :

[Unit]
Description=uWSGI service unit
After=syslog.target

[Service]
PIDFile=/run/uwsgi.pid
RemainAfterExit=yes
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -INT $MAINPID
Restart=always
StandardError=syslog
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target

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 :

[uwsgi]
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';
CREATE DATABASE site_db WITH OWNER site_user ENCODING 'UTF8';
GRANT all ON DATABASE site_db TO site_user;