您好,登錄后才能下訂單哦!
一、配置與安裝nginx環(huán)境
yum install nginx sqlite-devel sqlite zlib-devel openssl-devel MySQL-python unzip mariadb-server -y
cat /etc/nginx/conf.d/py.conf
server { listen 80; server_name 172.24.92.14; client_max_body_size 100M; location /static { alias /opt/BBS/static/; } location /media { alias /opt/BBS/media/; } location / { index index.html; include uwsgi_params; uwsgi_pass 127.0.0.1:9999; uwsgi_param UWSGI_SCRIPT BBS.wsgi; uwsgi_param UWSGI_CHDIR /opt/BBS; } }
重啟生效
systemctl restart nginx
二、配置Python3.6.8
解壓python文件
tar -xvf Python-3.6.8.tar.xz
cd /opt/Python-3.6.8
./configure --prefix=/opt/python-3-6-8/ --enable-optimization
make && make install
配置python 環(huán)境變量
vim /etc/profile
export PYTHON_HOME=/opt/python-3-6-8 export PATH=$PYTHON_HOME/bin:$PATH
source /etc/profile
三、安裝Django框架和uwsgi
配置pip安裝源
mkdir /root/.pip/
vim /root/.pip/pip.conf
[global] timeout = 6000 index-url = http://mirrors.aliyun.com/pypi/simple trusted-host = mirrors.aliyun.com
pip 安裝所需要的安裝包
cat uwsgi.txt
asn1crypto==0.24.0 beautifulsoup4==4.6.3 bs4==0.0.1 certifi==2018.4.16 cffi==1.11.5 chardet==3.0.4 Click==7.0 cryptography==2.3.1 Django==1.11.9 Flask==1.0.2 Flask-Cors==3.0.6 gevent==1.3.6 greenlet==0.4.15 idna==2.7 ItsDangerous==1.1.0 Jinja2==2.10 lxml==4.2.6 MarkupSafe==1.0 numpy==1.15.3 Pillow==5.3.0 pycparser==2.18 PyMySQL==0.9.2 pytz==2018.7 requests==2.19.1 selenium==3.141.0 six==1.11.0 urllib3==1.23 virtualenv==16.1.0 Werkzeug==0.14.1 wordcloud==1.5.0 uwsgi
pip3 install -r uwsgi.txt
配置uwsgi 測試頁
cat /opt/test.py
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello Django"]
運行測試程序頁
uwsgi --http 8001 --wsgi-file test.py &
訪問頁面:http://172.24.92.14:8001/
測試成功,關(guān)閉進程
pkill uwsgi
四、配置uwsgi項目
cat uwsgi.ini
[uwsgi] socket = 127.0.0.1:9999 master = true workers = 2 max-requests = 1000 buffer-size = 30000 pidfile = /run/uwsgi.pid daemonize = /var/log/uwsgi.log
啟動uwsgi
uwsgi --ini uwsgi.ini &
檢查啟動uwsgi程序
檢查端口:
創(chuàng)建項目:(我這里已有寫好的項目了,這里只是為了演示)
django-admin.py startproject BBS
修改訪問權(quán)限:
vim /opt/BBS/BBS/settings.py
添加mysql支持
cat /opt/BBS/BBS/__init__.py
import pymysql pymysql.install_as_MySQLdb()
配置數(shù)據(jù)庫(需要提前創(chuàng)建數(shù)據(jù)庫,數(shù)據(jù)庫名為,'bbs')
cat /opt/BBS/BBS/settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'HOST': '127.0.0.1', 'PORT': 3306, 'USER': 'root', 'PASSWORD': '123456', 'NAME': 'bbs', } }
啟動數(shù)據(jù)庫
systemctl restart mariadb
systemctl enable mariadb
寫入數(shù)據(jù)庫表:
python3 manage.py makemigrations
python3 manage.py migrate
五、運行項目:
cd /opt/BBS/ python3 manage.py runserver 0.0.0.0:8000
六、訪問測試
http://172.24.92.14/
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。