本文基于root用户安装配置,实现django项目名为trcode
sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python2.7-dev
sudo python2.7 -m pip install uwsgi
pip install Django==1.9.2
安装剩余环境包
项目根目录创建trcode_uwsgi.ini
# trcode_uwsgi.ini file
[uwsgi]
# Django-related settings
socket = :8000
# the base directory (full path)
chdir = /home/trcode
# Django s wsgi file
module = trcode.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
cd /home/trcode
项目启动uwsgi
uwsgi --ini trcode_uwsgi.ini
安装nginx同时添加nginx-gridfs
1、安装各种依赖包
apt-get install zlib1g-dev
apt-get install libpcre3 libpcre3-dev
apt-get install openssl libssl-dev
2、安装nginx-gridfs
apt-get install git
git clone https://github.com/mdirolf/nginx-gridfs.git
cd nginx-gridfs
git checkout v0.8
git submodule init
git submodule update
cd
3、安装nginx
wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar zxvf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure --with-openssl=/usr/include/openssl --add-module=../nginx-gridfs/
#进入主目录 gedit objs/Makefile修改一个小错误,把第3行的-Werror错误去掉,不然会报一个unused错误
make
make install
gedit /usr/local/nginx/conf/nginx.conf文件,http中添加如下内容。
user 修改为root
server {
# the port your site will be served on
listen 8001;
# the domain name it will serve for
server_name .example.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_read_timeout 2;
}
# Django static
location /static {
root /home/trcode/static; # your Django project's static files - amend as required
}
#Gridfs
#[root_collection]: 选择collection,如root_collection=blog, mongod就会去找blog.files与blog.chunks两个块,默认是fs
#[field]:查询字段,保证mongdb里有这个字段名,支持_id, filename, 可省略, 默认是_id
#[type]:解释field的数据类型,支持objectid, int, string, 可省略, 默认是int
#[user]:用户名, 可省略
#[pass]:密码, 可省略
location /file/ {
gridfs trdb
root_collection=fs
field=_id
type=objectid;
#这里的mongo以slave模式启动会有问题?
mongo 192.168.100.102:27017;
}
location /img/ {
gridfs trdb
root_collection=img
field=_id
type=objectid;
#这里的mongo以slave模式启动会有问题?
mongo 192.168.100.102:27017;
}
}
/usr/local/nginx/sbin/nginx 启动
/usr/local/nginx/sbin/nginx -s reload 重启nginx,访问8001成功
killall -9 uwsgi 关闭uwsgi进程