首先是安裝好nginx,配置web目錄,配置文件在confi.d中,
server {
# the port your site will be served on
listen80;
# the domain name it will serveforserver_name localhost; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location/media {
alias/var/www/myweb/media; # your Django project's media files - amend as required
}
location/static{
alias/var/www/myweb/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location/{
include/etc/nginx/uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass127.0.0.1:8001;
}
}
修改nginx配置文件后,需要重新啟動nginx
service nginx restart
把web文件git上傳到/var/www/myweb中去
可以使用pycharm的自動同步代碼工具,自動上傳代碼到服務器,速度特別快。
在settings.py中有一項wsgi的配置:
服務器端安裝插件
pip install django
pip install mysqlclient
pip install pillow
遷移數據
python manage.py makemigrations
python manage.py migrate
啟動服務
screen -S xyz
uwsgi-s:8001 -w web.wsgi
ctrl +a+d 退出screen
-----------------------
登陸后台發現沒有樣式了……只好把文件復制進去……
注意,在第二個Lib文件夾下的文件,復制到根目錄對應的文件夾中,上傳到服務器就好了。之前需要在服務器上創建超級管理員。