程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

CentOS 7+nginx+uwsgi deploy Django project

編輯:Python

This article mainly introduces server deployment Django Required configuration and uwsgi as well as nginx Configuration of , No introduction Python Installation and creation of virtual environment , It doesn't involve Mysql Database installation and configuration ,Python And virtual environments and Mysql You can search the Internet by yourself , Generally, there is no pit , It can be installed and configured successfully .

1. Upload the local project to the server

Use Xftp Connect to server , adopt Xftp Upload the local project to the specified location on the server , For example, I will upload to home/username Under the folder .

2. To configure Django project

In the project setting.py Inside , Comment out STATICFILES_DIRS, newly added STATIC_ROOT.

# STATICFILES_DIRS = (
# os.path.join(BASE_DIR,'static'),
# )
STATIC_ROOT = os.path.join(BASE_DIR,'static/'

To configure url.py file , stay urlpatterns New in :

url(r'media/(?P.*)$', serve, {"document_root": MEDIA_ROOT}),
url(r'^static/(?P.*)$', serve, {"document_root": STATIC_ROOT}),

Because it's used serve、MEDIA_ROOT and STATIC_ROOT, Import required :

from django.views.static import serve
from newblog.settings import MEDIA_ROOT, STATIC_ROOT

3. Collecting static files

Go to the project root , function

python manage.py collectstatic

4. install uwsgi

pip install uwsgi

5. install nginx

pip install uwsgiyum install nginx

6. To configure nginx

newly build nginx.cong file , Enter the following :

user root;
events{}
http{
include /etc/nginx/mime.types;
server{
listen 80;
server_name Your domain name ;
index index.html ;
root Your project directory ;
location /static {
alias Your project directory /static; # your Django project's static files - amend as required
}
location /media {
alias Your project directory /media;
}
# Finally, send all non-media requests to the Django server.
location / {
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass 127.0.0.1:8000;
}
}
}

7. Replace default nginx.conf file

Use the new nginx.conf File replacement /etc/nginx/nginx.conf file , It is recommended to back up the original before replacing nginx.conf file

8. To configure uwsgi file

newly build uwsgi.ini file , Enter the following :

# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = Your project directory
# Django's wsgi file
module = Project name .wsgi
# the virtualenv (full path)
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
virtualenv = Virtual environment path 

9. function uwsgi

uwsgi uwsgi.ini -d conf/uwsgi.log(-d Back for you to store log The path of )

10. function nginx

sudo /usr/sbin/nginx

11. Use the domain name to access your website

Enter your domain name in the browser , You can visit your website normally


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved