Ali cloud server Centos 7 under deployment Django + uWSGI + Nginx

Copyright: bloggers without consent, is prohibited reprint. Thank you! https://blog.csdn.net/cp_123321/article/details/87608832

surroundings

Python: 3.6

Django: 2.1

OS: CentOS 7 x86_64

uwsgi: 2.0.17
download Cmder     cmder.zip download   about 108M Once you have downloaded unzip to your desktop.

Open Cmder

Cmder official website   https://github.com/cmderdev/cmder/releases

 

Log on to Ali cloud server, click the remote connection can connect to the server,

Public network ip 


1. Open Cmder, linked to the public network server ip, ssh root @ public network ip   

2.yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel mysql-devel gcc gcc-devel python-devel
upgrade or install some dependencies python

3. wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
download python, just wget + Download python on it

4. python extracting compressed tar -zxvf Python-3.6.5.tgz

5.cd Python-3.6.5

6. Install the python, vim README.rst (command installed in this file that python-3.6.5 extract from the file)
to install the command
    ①. / The configure
    ②make
    ③make install
After installation, if the direct input or python 2.7 enter ./python is 3.6, (representative of the current folder)

7. Create a virtual environment ./python -m venv / root / python3env

8. Activate the virtual environment, the first cut to the parent directory python3env
Source python3env / bin / of an activate
deactivate exit the virtual environment


9. Open a new cmder, the project will move into the windows server (if not generated requirements.txt file, then run (just select a django project) at the PyCharm Terminal
PIP Freeze> requirements.txt the current environment the installation packages are listed in this file)

scp -r C:\Users\Administrator\Desktop\python\正课\27.Django2\mysite [email protected]:/root/mysite

10. (installed in the virtual environment) installation project dependencies, are requirements.txt in, so it is necessary to cut the project in
cd mysite
PIP install -r requirements.txt
After installation, test whether the normal operation of the project (python manage .py runserver)

11. Install uwsgi, installed in the virtual environment
pip install uwsgi

12. Download and install nginx (static file server)       
yum install nginx

Example 13 - (right) more - Network Security Group - Group Security Configuration - (upper side select) the security group list - Configuration Rule - (upper right) set of rules add security

Port 80/80 authorization object 0.0.0.0/0 (all are accessible)
port 8080/8080 authorization object 0.0.0.0/0 (so that all can access)

14 in the project 
vim settings.py modified ALLOWED_HOSTS = [ '*']
was added at = STATIC_URL '/ static /'
STATIC_ROOT = "static" (static load file path)

15. Create a file in the project
vim django_uwsgi.ini (from your own file name) to add the following content in it
[uwsgi]                   
# configuration required by uwsgi orientation django HTTP 
socket =: 8000                            
# Web project root                
chdir = / home / root1 / mysite (need to check the file path where the django_uwsgi.ini)          
# Module comes with the position of the specified item wsgi profile
Module = mysite.wsgi                              
# master process exists to allow                 
master to true =                                    
# number of open processes                  
processes = 3             
# server automatically clean up when you exit environmental            
vacuum = true  

16. Run the project (needs in a virtual environment, but also in the project mysite)
uwsgi --ini django_uwsgi.ini --buffer-size 30000
(the following, proved successful WSGI app 0 (mountpoint = '' ) ready in 6 seconds Interpreter 0x24eacd0 pid ON: 41241 (default App)
uWSGI running AS root, you CAN use --uid / - gid / - chroot Options)

17. Open a new window cmder link to the server

18. Configure nginx, cd / etc / nginx /
first nginx first line nginx.conf to root save, if you do not change, back when running the program will be reported insufficient privileges
cd conf.d
then new in the conf.d mysite.conf file
vim mysite.conf configuration reference may default.conf
Server {                                          
        port number # of the access port can not be the same items with                       
        the listen 8080;                             
        LOCATION / {                              
                the include / etc / Nginx / uwsgi_params;  
                uwsgi_pass 127.0.0.1:8000;        
        }
    # load static file path
    LOCATION / static {
    Alias / the root / the mysite / static;
}                                         
}    

19.nginx -t check the configuration file written if there are problems (insufficient privileges plus sudo)

20.ps -ef | grep nginx nginx View services running (if there is only one line, you need to open the nginx service, if more than one line, then nginx closed, then re-opened nginx service)

21.systemctl start nginx nginx open service, you need to run the program
(if enabled nginx service being given, the following will be prompted to enter this command to view the detailed error) journalctl -xe

22. (Cut to the first cmder, stop running the project, and then execute the following command)
and run python manage.py collectstatic in mysite project in ((you can see the command manage.py --help Python))
 LL static / command to view one more admin, css files

23. browser to access the public network ip: 8080
can be a normal visit
if prompted 503 error, then the need to turn off the firewall SELinux firewall.
vim / etc / selinux / config
position after SELINUX to disabled
Ali server has a firewall is turned off.

Guess you like

Origin blog.csdn.net/cp_123321/article/details/87608832