Under Centos7.6 Nginx + Uwsgi + Django deployment

                  I use Tencent cloud server is Centos7.6. The following configurations are operating under Root privileges.

1. python3

  1.1 installation dependencies 

sudo yum -y groupinstall "Development tools"
sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

  1.2 Download installation package Python3

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0a1.tar.xz

  1.3 unzip

takes -xvJf Python 3.7.0a1.tar.xz

  1.4 Parameter Configuration Editor

cd Python-3.7.0a1
./configure --prefix=/usr/local/bin/python3

  1.5 compile and install

make
make install

 

2. Install the virtual environment

  2.1 Installing the Virtual Environment

pip3 install virtualenv 
pip3 install virtualenvwrapper

  2.2 Create a folder to store virtual environments

mkdir /root/.virtualenvs

  2.3 Changing the configuration file .bashrc

vim ~/.bashrc
the Find / - name virtualenvwrapper.sh # View Path
= VIRTUALENVWRAPPER_PYTHON / usr / local / bin / python # specify python version virtualenvwrapper executed
WORKON_HOME = Export / root / .virtualenvs # virtual environment storage directory source /usr/local/bin/virtualenvwrapper.sh # virtualenvwrapper.sh directory

  2.4 Activate the Update configuration

source ~/.bashrc

  2.5 virtual environment basic commands

mkvirtualenv create a virtual environment
deactivate exit the virtual environment
workon view of virtual environments
workon name into the virtual environment Virtual Environment

 

3. Install PCRE library

  3.1 into the local folder

cd /usr/local/

  3.2 Download the installation package

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz

  3.3 extract the installation package

tar -zxvf pcre-8.33.tar.gz

  3.4 Parameter Configuration Editor

cd pcre-8.33
./configure

  3.5 compile and install

make && make install

  3.6 如果报错:configure: error: You need a C++ compiler for C++ support

Solution:
yum install -y gcc gcc-c++

 

 4. Installation SSL libraries

  4.1 into a local folder

cd /usr/local/

  4.2 Download the installation package

wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz

  4.3 extract the installation package

tar -zxvf openssl-1.0.1j.tar.gz

  4.4 Parameter Configuration Editor

cd openssl-1.0.1j
./config

  4.5 compile and install

make && make install

 

5. Install Zlib library

  5.1 into the local folder

cd /usr/local/

  5.2 Download the installation package

wget http://zlib.net/zlib-1.2.11.tar.gz

  5.3 extract the installation package

tar -zxvf zlib-1.2.11.tar.gz

  5.4 Parameter Configuration Editor

cd zlib-1.2.11
./configure

  5.5 compile and install

make && make install

 

6. Install Nginx

  6.1 into the local folder

cd /usr/local/

  6.2 Download the installation package

wget http://nginx.org/download/nginx-1.8.0.tar.gz

  6.3 extract the installation package

tar -zxvf nginx-1.8.0.tar.gz

  6.4 Parameter Configuration Editor

cd nginx-1.8.0
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module

  6.5 compile and install

make && make install

  6.6 Test start

/usr/local/nginx/sbin/nginx

  6.7 Setting the boot from Kai

we / etc / rc.local
/ Usr / local / nginx / sbin / nginx # added to the last row

  6.8 may encounter error

Error 1:
./configure: error: SSL modules require the OpenSSL library.
Solution:
yum -y install openssl openssl-devel

Error 2:
./configure: error: the HTTP gzip module requires the zlib library Solution: Behind -prefix then the following command: --with-pcre = / usr / local / pcre-8.36 means that the source path pcre-8.36. --with-zlib = / usr / local / zlib-1.2.8 refers zlib-1.2.8 source path.
 Error 3:
nginx: [emerg] still could not bind() Solution:
cd /usr/local/nginx/sbin/ ./nginx -s reload

 

7. Install Uwsgi

  7.1 Installation

pip3 install uwsgi

 

8. Install the Django (in a virtual environment)

  8.1 Installation

pip3 install django==1.11.11

 

9. Create a Django project (in a virtual environment)

  9.1 Creating project

 django-admin startproject project name

  9.2 Create a sub-applications

First, cd to the project directory
python manage.py startapp sub-application name

  9.3 Creating view function

cd to the next sub-application
vim views.py

Add to py file
from django.http import HttpResponse

def index(request):
    """
    index view
    : Param request: the request comprises a request object information
    : return : The response object
    """
    return HttpResponse("hello the world!")

  9.4 Creating Routing

meiduo vim / the Users / urls sub routing #

from django.conf.urls import url
from . import views

# Urlpatterns is django routing list variable automatic identification
urlpatterns = [ # Each routing information is required to construct the url function # Url (path view)
    url(r'^index/$', views.index),
]



vim meiduo/urls # 主路由 from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^', include('users.urls')), ]

  9.5 configuration settings file  

cd project directory / project name / 
1 . My son-register the application application name is users INSTALLED_APPS = [ 'users.apps.UsersConfig', ] 2 Set HOST ALLOWED_HOSTS = ['*']

  9.6 Nginx configuration file

vim /use/local/nginx/conf/nginx.conf

user  root;
worker_processes  1;

#error_log  logs/error.log;
logs #error_log / error.log Notice; 
# Set log log file error_log /var/log/nginx/nginx_error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include 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/nginx_access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name 127.0.0.1; root /home/python/Desktop/kaiyuan/static;
#charset koi8-r; #access_log logs/host.access.log main; # 设置首页访问路径 location =/ { root /home/python/Desktop/kaiyuan/static/;
index.html index.htm index;} = LOCATION / index.html index.html {index;} # Set static page access route LOCATION / static {Alias / Home / Python / Desktop / Kaiyuan / static;
autoindex ON;} Set # Django project LOCATION access path and uwsgi / {the include uwsgi_params; uwsgi_pass 127.0.0.1:9090 ; # here to write and uwsgi UWSGI_SCRIPT kaiyuan.wsgi consistent uwsgi_param;
uwsgi_param UWSGI_CHDIR / Home / Python / Desktop / kaiyuan;
}}

  9.7 configuration file Uwsgi

[Uwsgi]
# For the communications and Nginx
socket = 127.0.0.1:9090
# Django project root directory
chdir = /home/python/Desktop/kaiyuan
# Django project wsgi file
module = meiduo.wsgi # Start the primary process to manage other processes, other processes are child processes uwsgi master of
master = true # When the server exits automatically deleted unix socket file and pid file. = to true Vacuum # file specified pid = /home/python/Desktop/kaiyuan/uwsgi.pid PidFile 
# = log /home/python/Desktop/kaiyuan/uwsgi.log to daemonize
# autoloader py-autoreload = 1

  9.8 restart Nginx and Uwsgi

Restart Nginx
CD / usr / local / Nginx / sbin / 
./nginx - S # restart reload

Restart Uwsgi
cd / Home / Python / Desktop / kaiyuan /  # cd to your profile directory uwsgi --ini uwsgi.ini

 

 

Guess you like

Origin www.cnblogs.com/yinbohang/p/11794836.html