OpenResty 点滴

本文详细介绍了如何通过安装脚本在本地环境部署Nginx,并配置Lua模块处理HTTP请求,包括在指定目录下创建测试文件和配置文件,以及通过Nginx服务器提供静态和动态内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



安装脚本


$ cat build.sh 

#!/bin/bash

#


PCRE_DIR=$PWD/pcre-8.38


cd ngx_openresty-*

APPDIR=$HOME/s/apps/resty

LOGDIR=$HOME/s/logs/resty


./configure   \

        --prefix=$APPDIR        \

        --error-log-path=$LOGDIR/error.log    \

        --pid-path=$LOGDIR/resty.pid  \

        --lock-path=$LOGDIR/resty.lock \

        --http-log-path=$LOGDIR/access.log \

        --with-http_stub_status_module  \

        --with-pcre=$PCRE_DIR \

        --http-client-body-temp-path=$LOGDIR/client/ \

        --http-proxy-temp-path=$LOGDIR/proxy/   \

        --http-fastcgi-temp-path=$LOGDIR/fastcgi/    \

        --http-uwsgi-temp-path=$LOGDIR/uwsgi/    \

        --http-scgi-temp-path=$LOGDIR/scgi/    \

        --user=search   \

        --group=search  

make && make install



#        --without-pcre  \

#        --without-http_rewrite_module   \

#        --without-http_gzip_module      \


搭建测试环境

mkdir $HOME/work/resty

cd $HOME/work/resty

mkdir logs/ conf/  lua/ lua/app/

$ cat conf/nginx.conf 


worker_processes  1;

error_log logs/error.log;

events {

    worker_connections 1024;

}

http {

    server {

        listen 8080;


        location / {

            default_type text/html;

            content_by_lua '

                ngx.say("<p>hello, world</p>")

            ';

        }


        location ~ ^/app/([-_a-zA-Z0-9/]+) {

            set $path $1;

            content_by_lua_file lua/app/$path.lua;

        }


    }

}


$ cat lua/app/hello.lua 

ngx.say("Hello, Lua !")


$ cat nginx.sh 

#!/bin/bash

#

cd $(dirname $0)

APPDIR=$(pwd)

export PATH=$HOME/s/apps/resty/nginx/sbin:$PATH

nginx -p $APPDIR/ -c conf/nginx.conf $@


# 启动nginx server

./nginx.sh


# 测试结果

wget -O- -q -d 127.0.0.1:8080

wget -O- -q -d 127.0.0.1:8080/app/hello



转载于:https://my.oschina.net/kuerant/blog/603627

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值