• OpenResty 使用介绍


    yum安装

    http://openresty.org/cn/linux-packages.html#centos
    
    # add the yum repo:
    wget https://openresty.org/package/centos/openresty.repo
    sudo mv openresty.repo /etc/yum.repos.d/
    
    # update the yum index:
    sudo yum check-update
    
    # 安装openresty
    sudo yum install -y openresty
    
    # 如果你想安装命令行工具 resty
    sudo yum install -y openresty-resty

    # 包管理工具和文档管理工具
    yum install -y openresty-opm

    源码安装

    yum install readline-devel pcre-devel openssl-devel
    https://openresty.org/download/openresty-1.21.4.1.tar.gz
    tar xf openresty-1.21.4.1.tar.gz 
    ./configure
    make
    make install

     管理命令

    # 检查配置文件
    /usr/local/openresty/nginx/sbin/nginx  -t
    
    # 启动
    /usr/local/openresty/nginx/sbin/nginx 
    
    # 重新加载配置文件
    /usr/local/openresty/nginx/sbin/nginx -s reload
    
    # 停止
    /usr/local/openresty/nginx/sbin/nginx -s stop

    配置文件

    #user  nobody;
    worker_processes auto;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections 10024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        log_format  main  escape=json '{ "@timestamp": "$time_local", '
                             '"remote_addr": "$remote_addr", '
                             '"upstream_addr": "$upstream_addr",'
                             '"remote_user": "$remote_user", '
                             '"body_bytes_sent": "$body_bytes_sent", '
                             '"request_time": "$request_time", '
                             '"status": "$status", '
                             '"request": "$request", '
                             '"request_method": "$request_method", '
                             '"http_referrer": "$http_referer", '
                             '"http_x_forwarded_for": "$http_x_forwarded_for", '
                             '"http_user_agent": "$http_user_agent",'
                             '"http_uri": "$uri",'
                             '"http_host":"$http_host",'
                 '"req_header": "$req_header",'
                             '"resp_body":"$resp_body" }';
    
        access_log  logs/access.log  main;
    
        client_max_body_size 20m;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        #gzip  on;
        include /usr/local/openresty/nginx/conf/conf.d/*.conf;
    }
    nginx.conf
    server {
        listen 10001;
        lua_need_request_body on;
    
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-Port $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
        set $req_header "";
        header_filter_by_lua '
            local head = ngx.req.get_headers()
            for k,v in pairs(head) do 
                ngx.var.req_header = ngx.var.req_header .. string.format("%s : %s, ",k,v)
            end 
        ';
    
        set $resp_body "";
        body_filter_by_lua '
            local resp_body = string.sub(ngx.arg[1], 1, 1000)
            ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
            if ngx.arg[2] then
                ngx.var.resp_body = ngx.ctx.buffered
            end
        ';
    
        location / {  
            default_type text/html;
            content_by_lua '
                ngx.say("<p>Hello, World!</p>")
            ';
        }
    }
    hello.conf
  • 相关阅读:
    Exception in thread "main" java.io.IOException: Cannot run program "XX": CreateProcess error
    用eclipse打包mapreduce程序 运行出现解析路径错误的诡异问题
    HTMLParser学习笔记(一)
    Prim算法实现
    hadoop mapreduce 出现找不到 各种类的错误
    搜索引擎的基本原理
    ArrayList 和数组 在mapreduce编程中序列化
    读《做你自己》
    对于通过视频学习编程的建议
    长篇文档排版技巧
  • 原文地址:https://www.cnblogs.com/root0/p/16397570.html
Copyright © 2020-2023  润新知