This article describes how to launch and deploy a ** Django ** application on Alibaba Cloud.
This blog is a translation from the English version. You can check the original from here. We use some machine translation. We would appreciate it if you could point out any translation errors.
As a first prerequisite, virtualenv and virtualenv wrapper for Python-based applications You need to install .readthedocs.io/en/latest/?spm=a2c65.11461447.0.0.28a16cabOLprE3) to create a separate environment for your Python project. To do this, follow the steps below.
--Install pip
sudo apt-get install python-pip
--Installing virtualenv
sudo pip install virtualenv
--Create a dir
to store virtualenvs.
mkdir ~/.virtualenvs
--Installing virtualenvwrapper
sudo pip install virtualenvwrapper
--Set WORKON_HOME
in the virtualenv directory
export WORKON_HOME=~/.virtualenvs
--Add virtualenvwrapper.sh
to .bashrc
.
Add this line to the end of ~ / .bashrc
so that the virtualenvwrapper
command is loaded.
/usr/local/bin/virtualenvwrapper.sh
Exit the shell and reopen it, or reload .bashrc
with the .bashrc
or source ~ / .bashrc
command and you're ready to go.
apt-get install git
Sudo apt-get install nginx
Now let's get started with setting up and launching an Alibaba Cloud ECS instance.
Let's take a quick look at the steps to run an ECS instance using Alibaba Cloud Management Console.
Now you need to select the ** instance type ** you want to create. Based on your requirements, select the type of generation for your instance from the ** Generation ** tab. Generation types represent different instance types based on the configuration and computing power used.
Then select ** Network Type ** to launch your ECS instance. Depending on your needs, it can be either ** Classic Network ** or VPC (https://www.alibabacloud.com/en/product/vpc). In ** Classic Network **, Alibaba Cloud assigns IP addresses in a decentralized manner. Suitable for users who need simple and fast ECS. ** VPC ** is a logically isolated private network that supports dedicated connections. Suitable for users who are accustomed to more complex network management processes.
Select the ** System Disk ** type from the drop-down menu as needed. You can also click ** Add a disk ** to add a disk to this list.
In the Security Settings section, you can create a password for added security.
Review the configuration details and total price in the ** Overview ** section and click ** Buy Now **.
Click ** Activate ** to confirm your order and launch your instance.
Once the instance is launched, you can see it on the ** Instances ** tab of the console.
[Alibaba Cloud Management Console](https://account.alibabacloud.com/login/login.htm?oauth_callback=https%3A%2F%2Fhome-intl.console.aliyun.com%2F%3Fspm%3Da2c65.11461447.0.0.28 Now that we have created and launched an ECS instance using a16cabOLprE3 & lang = ja), let's see how to install and deploy the Django application.
mkvirtualenv DjangoApp
Use deactivate to terminate the new virtualenv. You can now switch environments with workon. Use the workon command to load and switch virtualenv.
workon DjangoApp
pip install Django
django-admin startproject todoApp
cd todoApp/
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver 0.0.0.0:8000
You can see that it is executed on port 8000 as follows.
You can manage your application by going to your admin panel, ** / admin **.
Now use Nginx (https://www.nginx.com/?spm=a2c65.11461447.0.0.28a16cabOLprE3) to place the application behind the web server.
--Change directory to Django Project directory --Execute the following command
python manage.py migrate
--Run the following command to collect all static files in a particular location.
Python manage.py collectstatic --noinput
--The developer is responsible for setting the STATIC_URL
path to the location where all static files are collected.
--These variables are defined in setting.py
in the Project directory.
1、STATIC_URL
2、STATICFILES_DIRS
3、STATIC_ROOT
pip install uWSG
Create a ** ini ** file to use to deploy your django application.
vim uwsgi.ini
--Save in ʻuwsgi.ini of ʻapplication dir
. See ** Python / WSGI Application Quick Start ** for how to write an ini file. Execute the following command to start the application.
uwsgi uwsgi.ini (your ini file)
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name localhost; location /static/ { include uwsgi_params; alias /root/todoApp/public/; } location / { include uwsgi_params; uwsgi_pass unix:/tmp/uwsgi.sock; } }
This article described how to deploy a Django application on Alibaba Cloud. In summary, the first step involved in doing this was to launch and run an ECS instance with Ubuntu as the OS, and then install and deploy the Django application on this instance. As part of the prerequisites for this tutorial, keep in mind that you must have completed the deployment and have a valid Alibaba Cloud account.
Below is a list of products related to this tutorial that will help you deploy your Django application in production scenarios.
Recommended Posts