首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 服务器的架构搭建

python 服务器的架构搭建

作者头像
py3study
发布2020-01-13 12:08:17
7480
发布2020-01-13 12:08:17
举报
文章被收录于专栏:python3python3

今天我将给大家介绍一种简单的python服务器的架构搭建:nginx + gunicron+supervisor + Django

Django 虽然自带了http相应服务,但不稳定,响应个数也很少,不能满足生产环境的需求,所以我们让nginx 来专门响应http请求,nginx的作用是:路由转发、负载均衡。 ubuntu环境 nginx服务器的安装: sudo apt-get install nginx nginx 服务器配置 http请求配置

upstream http_cluster {
    server 127.0.0.1:8886;
    server 127.0.0.1:8889;
}

server {
    listen 80;
    server_name www.your_web_address.com;
    access_log /data/log/nginx/access_.log;
    error_log /data/log/nginx/error_.log;
    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://http_cluster;
    }      
}

https 请求配置:

server {
    listen 443;
    ssl on;
    ssl_certificate  /etc/ssl/crt/your.crt;
    ssl_certificate_key  /etc/ssl/crt/your.key;
    server_name www.your_web_address.com;
    access_log /data/log/nginx/access.log;
    error_log /data/log/nginx/error.log;
    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://http_cluster;
    }  
}

sudo service nginx restart

pip install gunicorn sudo apt-get install supervisor 修改supervisord.conf chmod=0700 chown=项目运行的用户:项目运行的用户

cd /etc/supervisor/conf.d/ 新建一个配置文件my.conf

[program:my_program_1]
command= 运行命令
      -w 20
      -b 0.0.0.0:8886
      -k sync
      --log-level debug
    directory=项目位置
    numprocs=1
    user=deploy
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/supervisor/%(program_name)s.log
    stdout_logfile_maxbytes=100MB
    stdout_logfile_backups=10

[program:my_program_2]
command=运行命令
  -w 20
  -b 0.0.0.0:8889
  -k sync
  --log-level debug
    directory=项目位置
    numprocs=1
    user=deploy
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/supervisor/%(program_name)s.log
    stdout_logfile_maxbytes=100MB
    stdout_logfile_backups=10

pip install Django 下面就是django项目的搭建,我就不多说了,网上很多,我们来讲讲各个部分的作用吧。因为django 不能直接把nginx服务器, 但提供了wsgi接口,所以就需要一个中间层gunicron,同时gunicron支持多进程,异步功能,supervisor 的作用是用来管理gunicron服务,这一套环境布置基本满足中型网站的需求。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-07-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档