First, purchase the server
Recommended vultr Server, can also take a ladder, Link: portal
Operating system recommended Ubuntu 14.04 64-bit
Second, the purchase of domain names
Detailed See Baidu
Third, install the relevant software
#创建一个叫mu的用户
[Email protected]:~# useradd-m-s/bin/bash mu
# # #把新创建的用户加入超级权限组
[Email protected]:~# usermod-a-g sudo mu
# # #为新用户设置密码
# #注意在输密码的时候不会有字符显示, then knock
[Email protected]:~# passwd mu
#切换到创建的新用户
[Email protected]:~# su-mu
#切换成功
[Email protected]:~$
Update system
[Email protected]:~$ sudo apt-get update
[Email protected]:~$ sudo apt-get upgrade
Installing Nginx, Pip, virtualenv
[Email protected]:~$ sudo apt-get install Nginx
[Email protected]:~$ sudo apt-get install git python3 python3-pip
[Email protected]:~$ sudo pip3 install virtualenv
Start Nginx
[Email protected]:~$ sudo service nginx start
In the project configuration file, modify the following:
DEBUG = False
allowed_hosts = [' * ']
Static_url = '/static/'
#STATICFILES_DIRS = (
#os. Path.join (Base_dir, ' static '),
#)
#加入下面的配置
Static_root = Os.path.join (Base_dir, ' static ')
To build the installation dependency file, open cmd in the manage.py directory and run the following command
Pip Freeze > Requirements.txt
Push the project to GitHub
A single server may deploy multiple Web sites, and all site code is placed under the sites/directory.
home/mu/
sites/
tianbaoo.fun/
Env
Blog-sky
ackblog/
Env
Ackblog
awmonline/
Env
Awmonlin
The above is a file of three websites, each with its own Env and project
Examples of how to create two tianbaoo.fun below are also similar to the creation method.
[Email protected]:~$ mkdir-p ~/sites/tianbaoo.fun
[Email protected]:~$ cd ~/sites/tianbaoo.fun
[Email protected]:~/sites/tianbaoo.fun$ virtualenv--python=python3 env
#拉取项目文件
[Email protected]host:~/sites/tianbaoo.fun$ git clone https://github.com/tianbaoo/blog-sky.git
#激活虚拟环境并安装依赖
[Email protected]:~/sites/tianbaoo.fun$ Source Env/bin/activate
(ENV) [Email protected]:~/sites/tianbaoo.fun$ cd blog-sky/
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ pip Install-r requirements.txt
#收集静态文件
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ python manage.py collectstatic
#生成数据库
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ python manage.py migrate
#创建超级用户
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ python manage.py createsuperuser
Four, configuration Nginx
First create a new profile in the server's/etc/nginx/sites-available/directory, the file name I usually set as the domain name
/etc/nginx/sites-available/tianbaoo.fun
server {
CharSet Utf-8;
Listen 80;
server_name Tianbaoo.fun;
location/static {
alias/home/mu/sites/tianbaoo.fun/blog-sky/static;
}
Location/{
Proxy_set_header Host $host;
Tianbaoo.fun in #/tmp/tianbaoo.fun is the folder name in the Sites Directory
Proxy_pass Http://unix:/tmp/tianbaoo.fun.socket;
}
}
Multiple Web site projects, in the above file to write more than a few servers to listen to different ports can be described below.
Establishing a soft connection
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ sudo ln-s/etc/nginx/sites-available/tianbaoo.fun/etc/nginx/ Sites-enabled/tianbaoo.fun
Only see the Nginx Welcome page problem:
The default file configuration in the Sites-enabled folder overrides the configuration you have written, causing the configuration to not take effect and deleting the default file as normal
Installing Gunicorn
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ pip Install Gunicorn
Auto Start Gunicorn
Write a startup script that will automatically boot the Gunicorn when the server restarts. The script is located in the/etc/init/directory, and the script file name must end with. conf:
#/etc/init/gunicorn-tianbaoo.fun.conf
Start on net-device-up
Stop on shutdown
Respawn
Setuid mu
Chdir/home/mu/sites/tianbaoo.fun/blog-sky
Exec.. /env/bin/gunicorn--bind Unix:/tmp/tianbaoo.fun.socket blog-sky.wsgi:application
Start Gunicorn with the start command
(ENV) [Email protected]:~/sites/tianbaoo.fun/blog-sky$ sudo start gunicorn-tianbaoo.fun
#以后如果更新了代码, just run the following command to restart Nginx and Gunicorn to make the new code effective:
sudo service Nginx Reload
sudo restart Gunicorn-tianbaoo.fun
How far servers deploying multiple Web sites
We now have three Web site project folders: Tianbaoo.fun, Ackblog, awmonline, folders that correspond to their own virtual environments and actual project files
home/mu/
sites/
tianbaoo.fun/
Env
Blog-sky
ackblog/
Env
Ackblog
awmonline/
Env
Awmonlin
Now that we have successfully run the Blog-sky project in the Tianbaoo.fun folder, we are now going to add more ackblog and Awmonline projects.
Add the Ackblog item to the following first
[Email protected]:~$ mkdir-p ~/sites/ackblog
[Email protected]:~$ cd ~/sites/ackblog
[Email protected]:~/sites/ackblog$ virtualenv--python=python3 env
#拉取项目文件
[Email protected]:~/sites/ackblog$ git clone https://github.com/tianbaoo/ackblog.git
#激活虚拟环境并安装依赖
[Email protected]:~/sites/ackblog$ Source Env/bin/activate
(ENV) [Email protected]:~/sites/ackblog$ cd blog-sky/
(ENV) [Email protected]:~/sites/ackblog/ackblog$ pip Install-r requirements.txt
#收集静态文件
(ENV) [Email protected]:~/sites/ackblog/ackblog$ python manage.py collectstatic
#生成数据库
(ENV) [Email protected]:~/sites/ackblog/ackblog$ python manage.py migrate
#创建超级用户
(ENV) [Email protected]:~/sites/ackblog/ackblog$ python manage.py createsuperuser
We wrote the first project in the/etc/nginx/sites-available/tianbaoo.fun file. Blog-sky Server
Now we're also writing a second project in the Ackblog server information
View Code
To install Gunicorn in a Ackblog virtual environment after you have finished adding the server
(ENV) [Email protected]:~/sites/ackblog/ackblog$ pip Install Gunicorn
Set the Ackblog self-starting Gunicorn script
#/etc/init/gunicorn-ackblog.conf
Start on net-device-up
Stop on shutdown
Respawn
Setuid mu
Chdir/home/mu/sites/ackblog/ackblog
Exec.. /env/bin/gunicorn--bind Unix:/tmp/ackblog.socket ackblog.wsgi:application
(ENV) [Email protected]:~/sites/ackblog/ackblog$ sudo start gunicorn-ackblog
If you update the code later, just run the following command to restart Nginx and Gunicorn to make the new code effective:
sudo service Nginx Reload
sudo restart Gunicorn-ackblog
The third project Awmonlin the process steps and the second step are the same, that is, some parameters are different
[email protected]:~$ mkdir-p ~/sites/awmonline
[email protected]:~$ CD ~/sites/ Awmonline
[email protected]:~/sites/awmonline$ virtualenv--python=python3 env
#拉取项目文件
[email protected]:~/sites/awmonline$ git clone https://github.com/tianbaoo/AwmOnline.git
#激活虚拟环境并安装依赖
[ email protected]:~/sites/awmonline$ Source Env/bin/activate
(env) [email protected]:~/sites/ awmonline$ CD awmonline/
(env) [email protected]:~/sites/awmonline/awmonline$ pip Install-r requirements.txt
#收集静态文件
(env) [email protected]:~/sites/awmonline/awmonline$ python manage.py collectstatic
# Build Database
(env) [email protected]:~/sites/awmonline/awmonline$ python manage.py migrate
#创建超级用户
(env) [email protected]:~/sites/awmonline/awmonline$ python manage.py createsuperuser
In the/etc/nginx/sites-available/tianbaoo.fun file, we wrote the first project. Blog-sky Server and second project Ackblog server
And now we're also writing a third project in the Awmonline server information
View Code
To install Gunicorn in a awmonline virtual environment after you have finished adding the server
(ENV) [Email protected]:~/sites/awmonline/awmonline$ pip Install Gunicorn
Set the Awmonline self-starting Gunicorn script
#/etc/init/gunicorn-awmonline.conf
Start on net-device-up
Stop on shutdown
Respawn
Setuid mu
Chdir/home/mu/sites/awmonline/awmonlin
Exec.. /env/bin/gunicorn--bind Unix:/tmp/awmonline.socket AwmOnlin.wsgi:application
(ENV) [Email protected]:~/sites/awmonline/awmonlin$ sudo start gunicorn-awmonline
If you update the code later, just run the following command to restart Nginx and Gunicorn to make the new code effective:
sudo service Nginx Reload
sudo restart Gunicorn-awmonline
Ubuntu 14.04 deployment of Django projects