您的位置:首页 > 运维架构 > Nginx

nginx1.4.7+uwsgi+django1.9.2项目部署,liunx系统为ubuntu14.0.4。

2016-07-06 00:24 986 查看

本文基于root用户下进行部署,django项目名称为BDFS

1、  安装依赖包,终端输入命令

1)         环境依赖包

apt-get update

apt-get install python-pip

apt-get install python2.7-dev

python2.7 -m pip install uwsgi

2)         项目依赖包

pip install Django==1.9.2

剩下的pymongo包等,

2、  将项目拷贝至/home文件夹下,打开/home/BDFS文件夹,创建BDFS_uwsgi.ini文件,输入以下文字:

# BDFS_uwsgi.ini file

[uwsgi]

# Django-related settings

socket = :8000

# the base directory (full path)

chdir           = /home/BDFS

# Django s wsgi file

module          = BDFS.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

 

3、  启动uwsgi, ,终端输入命令

cd /home/BDFS

uwsgi --ini BDFS_uwsgi.ini

页面启动成功,显示如下信息,启动成功不要关闭终端

 

4、  安装nginx环境依赖包,新打开终端输入命令

apt-get install zlib1g-dev

apt-get install libpcre3 libpcre3-dev

apt-get install openssl libssl-dev

5、  安装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

gedit objs/Makefile把第3行的-Werror-删除,保存,关闭

make

make install

6、  修改nginx配置,终端输入命令

gedit /usr/local/nginx/conf/nginx.conf

拷贝以下文本,全覆盖

user  root;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

 

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       8001;

        server_name  localhost;

        charset     utf-8;

        #access_log  logs/host.access.log  main;

        location / {

            include uwsgi_params;

            uwsgi_pass 127.0.0.1:8000;

             uwsgi_read_timeout 2;

        }

        location /static {

            root  /home/BDFS;

        }

    }

}

7、  启动nginx ,终端输入命令

cd

sudo /usr/local/nginx/sbin/nginx           #启动

/usr/local/nginx/sbin/nginx -s reload   #重启nginx

 

 

 

8、  浏览器输入http://127.0.0.1:8001/既访问成功

注意事项:

启动nginx前,保证uwsgi服务正常启动,如果修改了项目源文件,需要关闭uwsgi服务,再重启才能刷新关闭命令killall  -9 uwsgi,没修改一次nginx配置文件也需要重启nginx服务,命令上面有

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: