Git Product home page Git Product logo

nginx-uwsgi-django-initctl's Introduction

nginx-uwsgi-django-initctl

使用nginx和uwsgi启动django

#1yum安装nginx(也可以源码包安装)

yum install nginx -y

##配置nginx

cd /etc/nginx/conf.d
vim cmdb.conf

文件内容如下:

# cmdb nginx conf

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name 192.168.56.101; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django static

    location /static {
        alias /data/www/cmdb/cmdb/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  0.0.0.0:8080;
        include     /data/www/cmdb/uwsgi_params; # the uwsgi_params file you installed
    }
}

将nginx目录下的uwsgi_params拷贝到django的相应目录中(创建一个软链接也可)

重启nginx,如果没有报错,说明nginx没有问题

#2安装配置uwsgi ##安装uwsgi

pip install uwsgi

##配置uwsgi参数 进入到django目录中,新建uwsgi.ini,内容如下:

[uwsgi]
socket = 0.0.0.0:8080
processes = 8
chdir = /data/www/cmdb/
pythonpath = /usr/bin/python
env = DJANGO_SETTINGS_MODULE=cmdb.settings
module = django.core.wsgi:get_wsgi_application()
daemonize = /var/log/cmdb.log
pidfile = /tmp/cmdb.pid

启动uwsgi

uwsgi --wsgi-file uwsgi.ini

这样子就能启动uwsgi了。但是如果要关闭或者重启uwsgi的话,目前只能通过脚本去killi掉相应的进程然后重新运行上面的命令。

#3uwsgi的启动,停止,重启方法

创建文件**/etc/init/uwsgi.conf**,内容如下:

description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/ --logto /var/log/cmdb.log

创建/etc/uwsgi/vassals/目录,将之前的uwsgi.ini文件cp到下面

运行命令initctl stop uwsgi

usage:

initctl start | stop | reload | restart uwsgi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.