openresty之旅

下载 、安装openresty

openresty官网链接
按照官网下载安装

tar -xzvf openresty-VERSION.tar.gz
cd openresty-VERSION/
./configure
make
make install

运行

# 默认安装路径为 /usr/local/openresty
# pwd 命令来查看"当前工作目录"的完整路径
/usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c /usr/local/openresty/nginx/conf/nginx.conf

--启动
/usr/local/openresty/nginx/sbin/nginx
--停止
/usr/local/openresty/nginx/sbin/nginx -s stop
--重启
/usr/local/openresty/nginx/sbin/nginx -s reload
--检验nginx配置是否正确
/usr/local/openresty/nginx/sbin/nginx -t

nignx 配置

启动文件为nginx.conf ,要支持多文件 需要加上 include conf.d/*.conf;

··· 省略 ···

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"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

	# 新建conf.d 新建不同的conf文件
    include conf.d/*.conf;

    server {
        listen       8099;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
··· 省略 ···

lua 编程

参考

set_by_lua

执行指定脚本和输入的值返回一个结果

-- set_by_lua $res <lua-script-str> [$arg1 $arg2...]
-- nginx conf 代码
--[[
location /foo {
 set $diff ''; # we have to predefine the $diff variable here
 set_by_lua $sum '
     local a = 32
     local b = 56
     ngx.var.diff = a - b;  -- write to $diff directly
     return a + b;          -- return the $sum value normally
	';
 echo "sum = $sum, diff = $diff";
]]

让systemd 管理

  1. vim打开/usr/lib/systemd/system/nginx.service
    内容如下
[Unit]
Description=The nginx process manager
After=network.target remote-fa.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/usr/local/openresty/nginx/sbin -s reload
ExecStop=/usr/local/openresty/nginx/sbin -s stop
          
[Install]
WantedBy=multi-user.target
  1. 重启system
systemctl daemon-reload

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值