二、maridb 和 redis
1. 安裝
sudo yum install mariadb-server
2. 啟動, 重新開機
sudo systemctl start mariadb
sudo systemctl restart mariadb
設定安全規則 配置mysql的端口
3. 設定bind-ip
vim /etc/my.cnf
在 [mysqld]:
下面加一行
bind-address = 0.0.0.0
4. 設定外部ip可以通路
先進入mysql才能運作下面指令:
mysql 直接進入就行
三、安裝nginx
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
1. sudo yum install epel-release
2. sudo yum install nginx
3. sudo systemctl start nginx
四、安裝virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
yum install python-setuptools python-devel
pip install virtualenvwrapper
編輯.bashrc檔案
export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
重新加載.bashrc檔案
source ~/.bashrc
建立虛拟環境
mkvirtualenv mxonline
進入虛拟環境
workon mxonline
安裝pip包
然後将requirements.txt檔案上傳到伺服器之後運作:
pip install -r requirements.txt
安裝依賴包
五、安裝uwsgi
pip install uwsgi
六、測試uwsgi
uwsgi --http :8000 --module MxOnline.wsgi
七、配置nginx
建立uc_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
八、将該配置檔案加入到nginx的啟動配置檔案中
sudo ln -s 你的目錄/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/
九、拉取所有需要的static file 到同一個目錄
在django的setting檔案中,添加下面一行内容:
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
運作指令
python manage.py collectstatic
十、運作nginx
sudo /usr/sbin/nginx
這裡需要注意 一定是直接用nginx指令啟動, 不要用systemctl啟動nginx不然會有權限問題
十一、通過配置檔案啟動uwsgi
建立uwsgi.ini 配置檔案, 内容如下:
# 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
十二、通路
http://你的ip位址/