***参考http://projectsedu.com/*****
*安装nginx
nginx:端口转发和静态文件代理
1.在终端输入命令:sudo apt-get install nginx
2.查看nginx进程是否启动:ps aux|grep nginx
3.在终端运行ifconfig查看ip地址,在浏览器中输入ip地址进行访问,出现welcome to nginx表示正常安装
*安装mysql
1.在终端输入 sudo apt-get install mysql-server
安装时提示设置root用户密码
2.查看mysql是否启动 ps aux|grep mysql
3.登录mysql命令 mysql -uroot -p
4.查看数据库 show databases
*navicat连接虚拟机设置
1.修改mysql配置 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 将ip改为0.0.0.0
2.修改配置之后,重启服务 sudo service mysql restart
3.mysql -uroot -p登录mysql修改登录权限
grant all privileges on . to root@"%" identified by "password" with grant option;
4.mysql刷新权限 flush privileges;
*安装虚拟环境并使workon生效
1.pip install virtualenv
2.pip install virtualenvwrapper
3.设置环境变量 vim ~/.bashrc
4 添加 export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
5.source ~/.bashrc 使环境变量生效
6.创建虚拟环境 mkvirtualenv test
**在本地虚拟环境导出开发包
1.进入虚拟环境 workon test
2.从本地导出开发包 pip freeze > requirements.txt
3.在linux创建文件 vim requirements.txt ,从本地复制开发包内容
4.在linux安装开发包 pip install -r requirements.txt
5.安装出错(mysql-config not found),运行 sudo apt-get install libmysqlclient-dev,再次运行pip install -r requirements.txt
*nginx配置
1.新建目录 mkdir conf
2.进入目录conf创建文件 vim mx_nginx.conf
3.配置mx_nginx.conf
the upstream component nginx needs to connect to
upstream django {
server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
configuration of the server
server {
the port your site will be served on
listen 80;
the domain name it will serve for
server_name 你的ip地址 ; # substitute your machine's IP address or FQDN
charset utf-8;
max upload size
client_max_body_size 75M; # adjust to taste
Django media
location /media {
alias 你的目录/Mxonline/media; # 指向django的media目录
}
location /static {
alias 你的目录/Mxonline/static; # 指向django的static目录
}
Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
4.拷贝 sudo cp ng_nginx.conf 到nginx文件配置目录 /etc/nginx/conf.d/
5.重新启动nginx sudo service nginx restart
6.在项目配置setting文件 vim MxOnline/settings.py 添加STATIC_ROOT = os.path.join(BASE_DIR, "static/")
7.拉取所有需要的static file 到同一个目录,运行 python manage.py collectstatic
**uwsgi安装和配置
1.安装uwsgi pip install uwsgi
2.测试uwsgi uwsgi --http :8000 --module MxOnline.wsgi(根据具体路径)
3.在浏览器输入ip地址查看网页是否正常显示
4.在conf目录下,新建 vim uwsgi.ini(复制如下内容,进行修改)
mysite_uwsgi.ini file
[uwsgi]
Django-related settings
the base directory (full path)
chdir = /home/bobby/Projects/MxOnline
Django's wsgi file
module = MxOnline.wsgi
the virtualenv (full path)
process-related settings
master
master = true
maximum number of worker processes
processes = 10
the socket (use the full path to be safe
socket = 127.0.0.1:8000
... with appropriate permissions - may be needed
chmod-socket = 664
clear environment on exit
vacuum = true
virtualenv = /home/bobby/.virtualenvs/mxonline
logto = /tmp/mylog.log
注:
chdir: 表示需要操作的目录,也就是项目的目录
module: wsgi文件的路径
processes: 进程数
virtualenv:虚拟环境的目录
5.进入conf目录,启动uwsgi
终端运行:uwsgi -i uwsgi.ini