LINUX配置Django

Posted yuanxiaohui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LINUX配置Django相关的知识,希望对你有一定的参考价值。


django项目:


依赖包
[[email protected] ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel -y

1.安装python3

[[email protected] ~]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
[[email protected] ~]# tar xf Python-3.6.2.tgz
[[email protected] ~]# cd Python-3.6.2/
[[email protected] Python-3.6.2]# ./configure --prefix=/usr/local/
[[email protected] Python-3.6.2]# make && make install
[[email protected] Python-3.6.2]# ./configure && make && make install


2.安装Django框架和uwsgi

vim re.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


pip3 install -i https://pypi.doubanio.com/simple/ -r re.txt
pip3 install -i https://pypi.doubanio.com/simple/ uwsgi

 

3.测试uwsgi是否正常,新建 test.py文件,内容如下:

[[email protected] ~]# vim 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 &

4.测试django是否正常,运行:

[email protected] ~]# django-admin.py startproject demosite
[[email protected] ~]# cd demosite
[[email protected] demosite]# python3 manage.py runserver 0.0.0.0:8002
在浏览器内输入:http://127.0.0.1:8002,检查django是否运行正常。


5.配置uwsgi


[[email protected] demosite]# vim /root/demosite/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 --ini /root/demosite/uwsgi.ini &


6.配置nginx


[[email protected] demosite]# vim /etc/nginx/conf.d/py.conf
server {
listen 80;
server_name 10.0.0.100;
client_max_body_size 100M;

location / {
index index.html;
include uwsgi_params;
uwsgi_pass 127.0.0.1:9999;
uwsgi_param UWSGI_SCRIPT demosite.wsgi;
uwsgi_param UWSGI_CHDIR /root/demosite;
}
}

重启nginx

 









































































以上是关于LINUX配置Django的主要内容,如果未能解决你的问题,请参考以下文章

linux怎么配置网络设置(linux怎么配置网络 连接外网)

linux 查看当前的网络配置

linux配置网络错误及解决

如何配置Linux网卡

linux配置ip应用灰色

请高手指点在linux系统中如何配置DNS