Ubuntu項(xiàng)目部署

***參考http://projectsedu.com/*****
*安裝nginx
nginx:端口轉(zhuǎn)發(fā)和靜態(tài)文件代理
1.在終端輸入命令:sudo apt-get install nginx
2.查看nginx進(jìn)程是否啟動(dòng):ps aux|grep nginx
3.在終端運(yùn)行ifconfig查看ip地址,在瀏覽器中輸入ip地址進(jìn)行訪問(wèn),出現(xiàn)welcome to nginx表示正常安裝

*安裝mysql
1.在終端輸入 sudo apt-get install mysql-server
安裝時(shí)提示設(shè)置root用戶密碼
2.查看mysql是否啟動(dòng) ps aux|grep mysql
3.登錄mysql命令 mysql -uroot -p
4.查看數(shù)據(jù)庫(kù) show databases

*navicat連接虛擬機(jī)設(shè)置
1.修改mysql配置 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 將ip改為0.0.0.0
2.修改配置之后,重啟服務(wù) sudo service mysql restart
3.mysql -uroot -p登錄mysql修改登錄權(quán)限
grant all privileges on . to root@"%" identified by "password" with grant option;
4.mysql刷新權(quán)限 flush privileges;

*安裝虛擬環(huán)境并使workon生效
1.pip install virtualenv
2.pip install virtualenvwrapper
3.設(shè)置環(huán)境變量 vim ~/.bashrc
4 添加 export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
5.source ~/.bashrc 使環(huán)境變量生效
6.創(chuàng)建虛擬環(huán)境 mkvirtualenv test

**在本地虛擬環(huán)境導(dǎo)出開(kāi)發(fā)包
1.進(jìn)入虛擬環(huán)境 workon test
2.從本地導(dǎo)出開(kāi)發(fā)包 pip freeze > requirements.txt
3.在linux創(chuàng)建文件 vim requirements.txt ,從本地復(fù)制開(kāi)發(fā)包內(nèi)容
4.在linux安裝開(kāi)發(fā)包 pip install -r requirements.txt
5.安裝出錯(cuò)(mysql-config not found),運(yùn)行 sudo apt-get install libmysqlclient-dev,再次運(yùn)行pip install -r requirements.txt

*nginx配置
1.新建目錄 mkdir conf
2.進(jìn)入目錄conf創(chuàng)建文件 vim mx_nginx.conf
3.配置mx_nginx.conf

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 server

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 taste

Django media

location /media {
alias 你的目錄/Mxonline/media; # 指向django的media目錄
}

location /static {
alias 你的目錄/Mxonline/static; # 指向django的static目錄
}

Finally, send all non-media requests to the Django server.

location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
4.拷貝 sudo cp ng_nginx.conf 到nginx文件配置目錄 /etc/nginx/conf.d/
5.重新啟動(dòng)nginx sudo service nginx restart
6.在項(xiàng)目配置setting文件 vim MxOnline/settings.py 添加STATIC_ROOT = os.path.join(BASE_DIR, "static/")
7.拉取所有需要的static file 到同一個(gè)目錄,運(yùn)行 python manage.py collectstatic

**uwsgi安裝和配置
1.安裝uwsgi pip install uwsgi
2.測(cè)試uwsgi uwsgi --http :8000 --module MxOnline.wsgi(根據(jù)具體路徑)
3.在瀏覽器輸入ip地址查看網(wǎng)頁(yè)是否正常顯示
4.在conf目錄下,新建 vim uwsgi.ini(復(fù)制如下內(nèi)容,進(jìn)行修改)

mysite_uwsgi.ini file

[uwsgi]

Django-related settings

the base directory (full path)

chdir = /home/bobby/Projects/MxOnline

Django's wsgi file

module = MxOnline.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/bobby/.virtualenvs/mxonline

logto = /tmp/mylog.log

注:
chdir: 表示需要操作的目錄,也就是項(xiàng)目的目錄
module: wsgi文件的路徑
processes: 進(jìn)程數(shù)
virtualenv:虛擬環(huán)境的目錄
5.進(jìn)入conf目錄,啟動(dòng)uwsgi
終端運(yùn)行:uwsgi -i uwsgi.ini

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容