ZabbixAPI+django+nginx简单的二次开发实例(三)

时间:2021-11-11 06:00:02

ZabbixAPI+django+nginx简单的二次开发实例(二)

步骤三,站点架构部分

本部分用到的软件

1,Nginx:接受访问请求,应答静态页面,转发动态请求至uwsgi

2,uwsgi:应答动态请求

3,Django:处理后台数据

4,supervisor:管理进程

首先安装Nginx

yum install epel-release

yum install python-devel nginx

修改配置文件

vim /etc/ngnix/ngnix.conf

user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { log_format main $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; #改成想要用的端口,网站名,我这里直接用ip了 server { listen 8888; server_name 192.168.10.162; charset utf-8; client_max_body_size 75M; #动态转发到uwsgi location / { uwsgi_pass unix:///tmp/pos.sock; include /etc/nginx/uwsgi_params; } #静态直接指定静态元素的路径 location /static { root /var/local/API/web/pos; } } include /etc/nginx/conf.d/*.conf; }

安装uwsgi

pip install uwsgi

如果你用的是Centos6+python2.7的话,这部可能会报错,因为Centos6默认的是python2.6

我们只能用源码安装uwsgi的源文件

wget

解压后make&&make install

然后更新python-devel

yum install python-devel

在用pip install uwsgi就会成功了。

新建一个uwsgi的配置文件

vi /API/web/pos/uwsgi.ini

[uwsgi] socket = /tmp/pos.sock http = 0.0.0.0:8000 master = 1 pidfile = /tmp/pos.pid processes = 4 chdir = /API/web/pos wsgi-file = pos/wsgi.py chmod-socket = 777

安装supervisor

pip install supervisor

生成默认配置文件

echo_supervisord_conf > /etc/supervisord.conf

*echo_supervisord_conf这个命令在python的bin下面

编辑配置文件

vim /etc/supervisor.conf

在文件最下面追加

[program:pos] command=http://www.mamicode.com/usr/local/python27/bin/uwsgi --ini /API/web/pos/uwsgi.ini directory=http://www.mamicode.com/API/web/pos startsecs=0 stopwaitsecs=0 autostart=true autorestart=true

这样就可以用supervisor控制project的启停了,,具体命令如下:

start supervisor(auto start all project):
supervisord -c /etc/supervisord.conf

start|stop|restart single|all project:
supervisorctl -c /etc/supervisord.conf start|stop|restart project|all

最后启动网站

service nginx start

supervisord -c /etc/supervisord.conf

打开网站