路過的關注一下哈 :python
1.安裝python3-pip -------------sudo apt-get install python3-pip
2.安裝虛擬環境和虛擬環境管理包
sudo pip3 install virtualenv (報錯的話須要把pip也安裝一下)
sudo pip3 virtualenvwrapper
在~/.bashrc 添加
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh (若是沒有virtualenvwrapper.sh就在這目錄下建立這個文件)
source .bashrc
建立虛擬環境:mkvirtualenv ShangOnline –p /usr/bin/python3
3.虛擬環境當中安裝項目所依賴的包(mysqlclient會出一個問題,須要首先安裝下面這個包)
咱們能夠經過 pip freeze > requirements.txt 將windows的虛擬環境安裝包相應信息導出來移動到ubuntu
pip3 install -r requirements.txt 在安裝過程當中mysqlclient會報錯,按照下面兩步走
sudo apt-get install libmysqlclient-dev
pip install mysqlclientmysql
4. 數據庫:
sudo apt-get install mysql-server
進入數據庫建立本身的帳戶而且分配全部的權限,而且刷新權限,在配置文件當中bind 0.0.0.0
在ubuntu 當中建立咱們用的數據庫shangonline,經過windows的Navicat將windows數據庫中的數據傳輸到ubuntu當中
將咱們的項目文件夾拖入到咱們的虛擬環境當中,進入項目python manage.py runserver保證能拉起項目
5.安裝uwsgi-------pip3 install uwsgi
測試uwsgi---------uwsgi --http :8000 --module ShangOnline.wsginginx
6. 安裝配置nginx------sudo apt-get install nginx
安裝完成會自動啓動nginx的服務,咱們在外部windows瀏覽器直接訪問ubuntu ip 會進入到nginx的環境界面
在項目 根目錄新建文件夾config-------新建sol_nginx.confweb
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the serversql
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 你的ip地址 ; # substitute your machine's IP address or FQDN
charset utf-8;數據庫
# max upload size
client_max_body_size 75M; # adjust to tastedjango
# Django media
location /media {
alias /home/ly/ShangOnline/static/media; # 指向django的media目錄
}ubuntu
location /static {
alias /home/ly/ShangOnline/static; # 指向django的static目錄
}windows
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
7. 將該配置文件加入到nginx的啓動配置文件中
sudo cp /home/ly/ShangOnline/config/sol_nginx.conf /etc/nginx/conf.d/
8. 拉取全部須要的static file 到同一個目錄
在django的setting文件中,添加下面一行內容:瀏覽器
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
運行命令
python manage.py collectstatic
9. 運行nginx
sudo /usr/sbin/nginx
這裏須要注意 必定是直接用nginx命令啓動, 不要用systemctl啓動nginx否則會有權限問題
10. 經過配置文件啓動uwsgi
新建uwsgi.ini 配置文件, 內容以下:
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/ly/ShangOnline/
# Django's wsgi file
module = ShangOnline.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 = /home/ly/Envs/ShangOnline
logto = /tmp/mylog.log
******注:
chdir: 表示須要操做的目錄,也就是項目的目錄
module: wsgi文件的路徑
processes: 進程數
virtualenv:虛擬環境的目錄
workon ShangOnline uwsgi -i /home/ly/ShangOnline/config/uwsgi.ini & 10.訪問 http://你的ip地址/