Automated configuration for Django in Centos7 with Nginx and Gunicorn

If you are Python Django developer, then each time you must create python environment and configure web server for your codes. For web server we can choose Apache with WSGI or Nginx with Gunicorn. For python environment we must install packages and of course install and configure one Database. In our article I used PostgreSQL. When you will execute this script it will wait input from your console. We must input there IP address, login, password and site name for Python Django WEB server. After install and configure Nginx with PostgreSQL script will ask about database name, login and password for your site. Then will create Virtual Environment for your codes and will ask input for Django admin credentials.

Python packages and libraries for your destkop or client server you can install via this script.

Git repository for all codes.

Our network topology will be as following:
DJ-ng-WEB

Lets start to show hot it works.

First time I will show script ./djgun.py. This script will install and configure all needed packages to the destination server. Then I will use ./add-vhost-djgun.py script for add new virtual host. If we will try to add existing domain name, the add-vhost-djgun.py script will check and warn us about this.

fpyvenv ngdjgunpy # <span style="color: #0000ff"><strong>./djgun.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.233</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>unixmen.com</strong></span>
This is CentOS server...
Please be patient it will take some time!!!
PostgreSQL service already running...
Enter name for new database: <span style="color: #0000ff"><strong>unixmendb</strong></span>
Enter new user name for access unixmendb: <strong><span style="color: #0000ff">unixmenuser</span></strong>
Enter pass for unixmenuser:
Repeat pass for unixmenuser:
Please enter admin username for DjangoAdmin: <span style="color: #0000ff"><strong>admin</strong></span>
Please enter admin email for DjangoAdmin: <span style="color: #0000ff"><strong>admin@unixmen.com</strong></span>
Minimal length of password is 8. One upper case, one number and one lower case must be there...
Please enter Django admin password for admin user:
Please repeat Django admin password for admin user:
Congratulations, your Gunicorn service is already working!!!
Congratulations, you have already installed and configured nGinx with Gunicorn!!!

If we will try to add existing domain name with the ./djgun.py script, it will warn us. For add new virtual host please use the ./add-vhost-djgun.py script.

fpyvenv ngdjgunpy # <span style="color: #0000ff"><strong>./djgun.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.233</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>unixmen.com</strong></span>
This is CentOS server...
Please be patient it will take some time!!!
You have already installed and running Nginx web server...
If you want add new VirtualHost, please use <strong>./add-vhost-djgun.py</strong> script.

Now we will try to add new virtual host to destination server:

fpyvenv ngdjgunpy # <span style="color: #0000ff"><strong>./add-vhost-djgun.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.233</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>linuxmen.com</strong></span>
This is CentOS server...
You have already running Nginx and PostgreSQL web server...
Enter name for new database: <span style="color: #0000ff"><strong>linuxmendb</strong></span>
Enter new user name for access linuxmendb: <span style="color: #0000ff"><strong>linuxmenuser</strong></span>
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
Please enter admin username for DjangoAdmin: <span style="color: #0000ff"><strong>admin</strong></span>
Please enter admin email for DjangoAdmin: <span style="color: #0000ff"><strong>admin@linuxmen.com</strong></span>
Minimal length of password is 8. One upper case, one number and one lower case must be there...
Please enter Django admin password for admin user:
Please repeat Django admin password for admin user:
Congratulations, your Gunicorn service is already working!!!
Congratulations, you have successfully added new nginx virtual host and gunicorn socket!!!

At the end try to add existing virtual host with ./add-vhost-djgun.py script:

fpyvenv ngdjgunpy # <span style="color: #0000ff"><strong>./add-vhost-djgun.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.233</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>linuxmen.com</strong></span>
This is CentOS server...
Entered domain name linuxmen.com is already exists on the 172.16.100.233 server!!!
Please enter different name than "<strong>linuxmen.com</strong>" !!!

Add domain names to your desktop hosts file and test via browser:
linuxmen

unixmen