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 setting.py 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 wsgi.py 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 manager.py 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 dongpouu.com; 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 127.0.0.1:8000# 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 www.dongpouu.com (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)