在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑。
1 Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-130-generic x86_64)
1 apt-get install uwsgi 2 apt-get install nginx
(注:如果下载异常出现权限问题,在命令前添加sudo)
例如:项目名为mysite
1 Django-admin startproject mysite
说明:Linux系统内置了python2.7,如果你的Django项目依赖于Python3,请使用pip3 install django安装Python3环境下的Django框架
1 python3 manage.py runserver 0.0.0.0:8001
运行正常则关闭,进行下一步...
1.ip为服务器ip地址
1 Allow_host = [‘134.175.25.77‘, ‘localhost‘]
2.静态目录设置
1 STATIC_ROOT = os.path.join(BASE_DIR, ‘/var/www‘)
3.支持debug
1 DEBUG = True
4.迁移静态文件目录
1 python3 manage.py collectstatic
1.编辑nginx配置文件
1 sudo vim /etc/nginx/nginx.conf
2.新建一个mysite.conf文件(提示权限问题,自行在命令前加上sudo)
1 touch /etc/nginx/mysite.conf 2 vim /etc/nginx/mysite.conf
3.mysite.conf内容如下:
1 server{ 2 listen 80; 3 server_name localhost; 4 charset utf-8; 5 access_log off; 6 location /static { 7 alias /var/www/; 8 } 9 location / { 10 uwsgi_pass 127.0.0.1:8001; 11 include /etc/nginx/uwsgi_params; 12 } 13 }
4.将mysite引入到nginx.conf下的http配置下
#include mysite.conf
5.注释nginx.conf以下配置选项
1 include /etc/nginx/conf.d/*.conf; 2 include /etc/nginx/sites-enabled/*;
1.建立配置文件socket.xml文件(位置如下)
1 ├── db.sqlite3 2 ├── manage.py 3 ├── mysite 4 │ ├── __init__.py 5 │ ├── __pycache__ 6 │ │ ├── __init__.cpython-35.pyc 7 │ │ ├── settings.cpython-35.pyc 8 │ │ ├── urls.cpython-35.pyc 9 │ │ └── wsgi.cpython-35.pyc 10 │ ├── settings.py 11 │ ├── urls.py 12 │ └── wsgi.py 13 ├── mysitepro.ini 14 ├── socket.xml 15 └── uwsgi.log
2.socket.xml内容
1 <uwsgi> 2 <socket>:8001</socket> 3 <chdir>/home/ubuntu/mysite</chdir> 4 <module>mysite.wsgi</module> 5 <processes>4</processes> 6 <daemonize>uwsgi.log</daemonize> 7 </uwsgi>
1 killall -9 uwsgi 2 uwsgi -x socket.xml 3 service nginx start 4 service nginx reload
python3 manage.py runserver 0.0.0.0:8004
1 http://134.175.25.77:8004/admin/
原文:https://www.cnblogs.com/kisun168/p/10000544.html