• 使用Nginx代理Django


    一、准备环境

    检查python版本以及pip版本

    [root@linux-node01 src]# python --version
    Python 2.7.5
    [root@linux-node01 src]# pip --version
    pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)
    [root@linux-node01 src]# 

    如果没有安装pip

    在安装了epel源的情况下,直接yum就可以安装python3.4

    yum install python34 -y
    python3 --version

    没有自带pip3,从官网安装

    wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py   # 执行下载
    python3 get-pip.py                                                 # 改为 python  get_pip.py即可安装
    pip3 -V

    二、安装nginx

    1. openresty简介

    openresty是一个nginx套件,而非fork,这表示 :
    
    openresty没有修改nginx源码,这和Tengine等项目不同。
    openresty是给原生的nginx增加了很多功能插件,例如:支持lua脚本,支持在nginx配置文件中获取post参数,支持lua脚本连接mysql和redis等
    openresty中的nginx是较新版,但不一定是最新版
    openresty的官网是:
    
    https://openresty.org/cn/

    2. 安装步骤

    #安装依赖的软件包
    
    yum install -y readline-devel ncurses-libs pcre-devel perl make postgresql-devel geoip-devel libdrizzle-devel geoip-devel yum -y install gcc gcc-c++
    下载最新版openresty
    
    wget https://openresty.org/download/openresty-1.11.2.1.tar.gz
    # 解压它
    tar zxvf openresty-1.11.2.1

    3. 配置openresty

    ./configure --conf-path=/etc/openresty/openresty.conf 
    --error-log-path=/var/log/openresty/error.log 
    --http-client-body-temp-path=/var/lib/openresty/body 
    --http-fastcgi-temp-path=/var/lib/openresty/fastcgi 
    --http-log-path=/var/log/openresty/access.log 
    --http-proxy-temp-path=/var/lib/openresty/proxy 
    --lock-path=/var/lock/openresty.lock --pid-path=/var/run/openresty.pid 
    --with-debug --with-http_dav_module --with-http_flv_module 
    --with-http_geoip_module --with-http_gzip_static_module --with-http_realip_module
     --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module 
     --with-ipv6 --with-mail --with-mail_ssl_module --prefix=/usr/local/openresty 
     --with-luajit --with-http_postgres_module --with-http_iconv_module
    View Code
    如果想用nginx连接mysql,需要在配置命令最后添加
    
    --with-http_drizzle_module

    4. 编译安装

    待配置过程完成以后
    
    gmake
    gmake install
    建立必要的工作目录
    
    mkdir /var/lib/openresty;
    mkdir /var/lib/openresty/body;
    建立软链接,方便调用
    
    ln -s /usr/local/openresty/nginx/sbin/nginx /usr/bin/nginx

    5. 报错信息

    安装pcre
    
    objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_regex_free_study_data':
    /opt/openresty-1.11.2.1/build/nginx-1.11.2/../ngx_lua-0.10.6/src/ngx_http_lua_regex.c:1959: undefined reference to `pcre_free_study'
    objs/addon/src/ngx_http_lua_regex.o: In function `ngx_http_lua_ffi_destroy_regex':
    /opt/openresty-1.11.2.1/build/nginx-1.11.2/../ngx_lua-0.10.6/src/ngx_http_lua_regex.c:2353: undefined reference to `pcre_free_study'
    collect2: ld 返回 1
    gmake[2]: *** [objs/nginx] 错误 1
    gmake[2]: Leaving directory `/opt/openresty-1.11.2.1/build/nginx-1.11.2'
    gmake[1]: *** [build] 错误 2
    gmake[1]: Leaving directory `/opt/openresty-1.11.2.1/build/nginx-1.11.2'
    gmake: *** [all] 错误 2
    说明当前系统中的pcre无法使用,需要自己下载,下载地址
    
    https://sourceforge.net/projects/pcre/files/pcre/8.39/
    wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz
    tar zxvf pcre-8.39.tar.gz
    在配置openresty时添加如下配置
    
    --with-pcre=../pcre-8.39

    6. 检查配置

    # 过滤生成nginx配置文件
    [root@linux-node01 src]# grep -Ev "^$|#" /etc/openresty/openresty.conf >/etc/openresty/nginx.conf
    # 检查配置文件
    [root@linux-node01 src]# /usr/local/openresty/nginx/sbin/nginx -t 
    nginx: the configuration file /etc/openresty/openresty.conf syntax is ok
    nginx: configuration file /etc/openresty/openresty.conf test is successful
    [root@linux-node01 src]# /usr/local/openresty/nginx/sbin/nginx -c /etc/openresty/nginx.conf -t
    nginx: the configuration file /etc/openresty/nginx.conf syntax is ok
    nginx: configuration file /etc/openresty/nginx.conf test is successful
    [root@linux-node01 src]# 

    7. 启动服务:8080端口

    [root@linux-node01 src]# /usr/local/openresty/nginx/sbin/nginx -c /etc/openresty/nginx.conf 
    [root@linux-node01 src]# 
    [root@linux-node01 src]# netstat -lnpt |grep 80
    tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      3605/nginx: master  
    tcp6       0      0 :::80                   :::*                    LISTEN      1390/httpd          
    You have new mail in /var/spool/mail/root
    [root@linux-node01 src]# 

    三、安装uwsgi

    1. 操作命令

    pip install uwsgi

    2. 检查安装

    [root@linux-node01 openresty]# uwsgi --version
    2.0.17
    [root@linux-node01 openresty]# 

    3. 创建uwsgi配置文件

    [root@linux-node01 openresty]# cat /etc/uwsgi9090.cnf
    [uwsgi]
    socket = 127.0.0.1:9090
    master = true         //主进程
    vhost = true          //多站模式
    no-site = true        //多站模式时不设置入口模块和文件
    workers = 2           //子进程数
    reload-mercy = 10     
    vacuum = true         //退出、重启时清理文件
    max-requests = 1000   
    limit-as = 512
    buffer-size = 30000
    pidfile = /var/run/uwsgi9090.pid    //pid文件,用于下面的脚本启动、停止该进程
    daemonize = /website/uwsgi9090.log
    [root@linux-node01 openresty]# 

    4. 设置完成后,在终端运行

      

  • 相关阅读:
    redis缓存问题解决方案
    JVM 2-垃圾收集及内存分配策略
    JVM 1-内存管理
    mysql数据库基础
    事务学习
    使用redis分布式锁来解决集群项目的定时任务冲突问题
    Spring AOP学习
    Spring IOC
    java语言基础7--线程相关类
    多重背包的二进制优化——DP
  • 原文地址:https://www.cnblogs.com/supery007/p/8638705.html
Copyright © 2020-2023  润新知