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 # ./djgun.py
Please enter WEB server IP address: 172.16.100.233
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
This is CentOS server...
Please be patient it will take some time!!!
PostgreSQL service already running...
Enter name for new database: unixmendb
Enter new user name for access unixmendb: unixmenuser
Enter pass for unixmenuser:
Repeat pass for unixmenuser:
Please enter admin username for DjangoAdmin: admin
Please enter admin email for DjangoAdmin: admin@unixmen.com
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 # ./djgun.py
Please enter WEB server IP address: 172.16.100.233
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
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 ./add-vhost-djgun.py script.

Now we will try to add new virtual host to destination server:
fpyvenv ngdjgunpy # ./add-vhost-djgun.py
Please enter WEB server IP address: 172.16.100.233
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: linuxmen.com
This is CentOS server...
You have already running Nginx and PostgreSQL web server...
Enter name for new database: linuxmendb
Enter new user name for access linuxmendb: linuxmenuser
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
Please enter admin username for DjangoAdmin: admin
Please enter admin email for DjangoAdmin: admin@linuxmen.com
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 # ./add-vhost-djgun.py
Please enter WEB server IP address: 172.16.100.233
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: linuxmen.com
This is CentOS server...
Entered domain name linuxmen.com is already exists on the 172.16.100.233 server!!!
Please enter different name than "linuxmen.com" !!!

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

unixmen

Advertisements