DJANGO+NGINX+UWSGI Deployment of production environments (Ubuntu16.04)

Source: Internet
Author: User

One, the preparatory work:

The code must be able to run locally!

The installation of various basic packages is slightly by default already installed PYTHON3,NGINX,UWSGI and other basic dependencies, note the version issue.

Modify the local file as follows (change to production mode, turn debug off, add host and static file address):

Create a new Uwsgi.ini configuration file anywhere in the project directory:

#Dongpouu_uwsgi.ini File[Uwsgi]#django-related SettingsSocket=: 8000#ports for Real services#Django Project root directory (absolute path)ChDir =/home/Dongpouu#The location of the file in the projectmodule =Dongpouu.wsgi#process-related Settings#Mastermaster =true#number of processes runningprocesses = 1#... with appropriate permissions-may be needed#Chmod-socket = 664#clear environment on exitVacuum = True

Then hit a zip package, upload to the server via FTP, note that the upload path to the same address within the Uwsgi.ini:

Then, in the project root directory, run a command to collect the static files (because in production mode, Django will no longer automatically manage static paths.) The latter will be managed by configuration to Nginx):

Python3 collectstatic

Configure Nginx. Under the/etc/nginx/directory, locate the nginx.conf file, open it with vim, and add the following inside the http{} . This is not the only way to configure, the others have tried a lot of pits, and finally this kind of success! 、

 server { #   Here is the Nginx port, be careful not to confuse with Django, all the configuration inside only this port is not the same as other places!!!         Listen 80;        server_name;        CharSet UTF  -8;  #   This save log file  access_log/var/log/        Nginx/dongpouu_access.log;        Error_log /var/log/nginx/dongpouu_error.log;            Location /static//home/dongpouu/static//med            Ia/ {AutoIndex on; Alias /home/dongpouu/media/;  #这里按照自己的实际情况来, including the following 

# Same UWSGI content
Uwsgi_pass link time-out
Uwsgi_read_timeout 30

The last three commands, the deployment takes effect (the failed self-troubleshooting must be a configuration problem):

Killall-9 Uwsgi # kills a running UWSGI service
Uwsgi--ini Dongpouu_uwsgi.ini # Note to CD to the file corresponding to the directory, this command successfully on behalf of the Django project run up smoothly!

Service Nginx Reload # reload Nginx

Finally visit (your own URL, or direct access to the server's public IP) to see the effect.

DJANGO+NGINX+UWSGI Deployment of production environments (Ubuntu16.04)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.