1.安装nginx
yum install -y nginx(需要epel源)
2.安装uwsgi
yum groupinstall "Development tools" yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel python-devel pip install uwsgi
3.安装django
pip install django==1.11
4.创建django项目
#/data 目录下创建mysite项目django-admin startproject mysite
5.创建app
python manage.py startapp app01
6.修改mysite/settings.py
ALLOWED_HOSTS = [‘*‘]
7.关闭防火墙
关闭内置防火墙selinux
#暂时停止selinxu setenforce 0 #永久关闭selinux vi /etc/selinux/conf 修改如下行 SELINUX=enforcing 重启机器,使得selinx永久关闭
关闭软件防火墙
iptables -F #清空防火墙规则 systemctl stop firewalld #关闭软件防火墙 systemctl disable firewalld #删除iptables的开机自启
8、uwsgi配置文件
uwsgi支持ini、xml等多种配置方式,本文以 ini 为例, 在/etc/目录下新建uwsgi.ini,添加如下配置: #三种配置方法可任选其中一种,选择哪种则将哪种的注释打开即可 [uwsgi] http = 0.0.0.0:8000 #第一种配置方法 #socket = 0.0.0.0:8000 #第二种配置方法 #the local unix socket file than commnuincate to Nginx #socket = /data/mysite/mysite.socket #第三种配置方法 # the base directory (full path) chdir = /data/mysite # Django‘s wsgi file wsgi-file = mysite/wsgi.py # maximum number of worker processes processes = 4 #thread numbers startched in each worker process threads = 2 # clear environment on exit vacuum = true daemonize = /data/mysite/uwsgi.log py-autoreload=1
第一种使用http = 0.0.0.0:8000,对应nginx配置文件如下:
vi /etc/nginx/nginx.conf location / { include /etc/nginx/uwsgi_params; proxy_pass http://127.0.0.1:8000; }
第二种使用socket = 0.0.0.0:8000,对应nginx配置文件如下:
vi /etc/nginx/nginx.conf location / { include /etc/nginx/uwsgi_params; uwsgi_pass 127.0.0.1:8000; }
第三种使用socket = /data/mysite/mysite.socke,对应nginx配置文件如下:
vi /etc/nginx/nginx.conf location / { include /etc/nginx/uwsgi_params; uwsgi_pass unix:/data/mysite/mysite.socket; }
启动uwsgi
uwsgi --ini /etc/uwsgi.ini
启动nginx
systemctl start nginx
此时可以通过主机地址:80端口访问我们的django项目啦!
原文地址:https://www.cnblogs.com/fengchong/p/10420831.html
时间: 2024-10-10 12:11:15