环境:
1.centos7
2.python2
3.django1.11
4.nginx
1.安装python虚拟环境
pip install virtualenv
2.创建虚拟环境
mkdir django_project cd django_project virtualenv venv
3.在虚拟环境里安装django
source source venv/bin/activate pip install django
4.创建django项目
django-admin startproject mysite cd mysite #测试项目,测试正常后,ctrl+c结束 python manage.py runserver #django相关请查看我的相关博客,或者到官网学习
5.安装nginx
yum install nginx -y
6.全局安装或者虚拟环境uwsgi
pip install uwsgi
7.编写uwsgi文件
[uwsgi] #socket = 127.0.0.1:3031 socket = /run/mysite.sock chdir = /opt/django_project/mysite wsgi-file = mysite/wsgi.py #http = 127.0.0.1:9191 virtualenv = /opt/django_project/venv daemonize = /var/log/uwsgi.log processes = 4 uid = root gid = root
8.编写并导入nginx配置文件
vim /etc/nginx/vhost/django.conf
server { listen 8000 default_server; listen [::]:8000 default_server; server_name localhostA; include /etc/nginx/default.d/*.conf; index index.html index.htm index.php; location / { include uwsgi_params; uwsgi_pass unix:///run/mysite.sock; } }
在/etc/nginx/nginx.conf里添加以下内容
include /etc/nginx/vhost/*.conf;
9.启动uwsgi和重启nginx
10.项目详情