openresty 安装(docker)
openresty 安装
docker pull openresty/openresty
huli@hudeMacBook-Pro conf % docker exec -it openresty bash # 工作目录 root@7bd203df440c:/# cd /usr/local/openresty root@7bd203df440c:/usr/local/openresty# ls bin luajit lualib nginx openssl111 pcre site zlib # nginx目录 root@7bd203df440c:/usr/local/openresty# cd nginx root@7bd203df440c:/usr/local/openresty/nginx# ls conf html logs sbin # nginx配置目录 root@7bd203df440c:/usr/local/openresty/nginx# ls conf fastcgi.conf koi-win scgi_params fastcgi.conf.default mime.types scgi_params.default fastcgi_params mime.types.default uwsgi_params fastcgi_params.default nginx.conf uwsgi_params.default koi-utf nginx.conf.default win-utf
root@7bd203df440c:/usr/local/openresty/nginx/conf# ls /etc/nginx/conf.d default.conf root@7bd203df440c:/usr/local/openresty/nginx/conf# cat /etc/nginx/conf.d/default.conf # nginx.vh.default.conf -- docker-openresty # # This file is installed to: # `/etc/nginx/conf.d/default.conf` # # It tracks the `server` section of the upstream OpenResty's `nginx.conf`. # # This config (and any other configs in `etc/nginx/conf.d/`) is loaded by # default by the `include` directive in `/usr/local/openresty/nginx/conf/nginx.conf`. # # See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files # server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/local/openresty/nginx/html; index index.html index.htm; } location /lua { default_type "applictaion/json"; content_by_lua "ngx.say('hello gtlx')"; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/openresty/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root /usr/local/openresty/nginx/html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
docker run -it -d -p 8080:80 \ -v /Users/huli/lua/openresty/conf/default.conf:/etc/nginx/conf.d/default.conf \ --name openresty openresty/openresty
&bsp;
opm 命令
Starting at version 1.11.2.2, OpenResty for Linux includes a package manager called opm, which can be found at /usr/local/openresty/bin/opm. * 从1.11.2.2版本开始,linux openresty默认安装opm工具管理包 * 存放目录为:/usr/local/openresty/bin/opm opm is built in all the images except alpine and buster and bullseye. * buster、bullseye版本的镜像没有安装opm To use opm in the alpine image, you must also install the curl and perl packages; they are not included by default because they double the image size. You may install them like so: apk add --no-cache curl perl. * 在alpine镜像中使用opm,需要安装curl、perl命令 * 安装方式:apk add --no-cache curl perl To use opm within the bullseye image, you can either use the bullseye-fat image or install the openresty-opm package in a custom build (which you would need to do to install your own opm packages anyway), as shown in this buster example. * 在bullseye镜像中使用opm,可以使用bullseye-fat镜像 * 或者在
自定义的版本中安装opm
# 克隆仓库到本地
https://github.com/openresty/docker-openresty.git
# 使用centos7 Dockerfile
复制nignx.conf、nginx.vh.default.conf到centos7目录
# 构建镜像文件
docker build -t lihu12344/openresty .
docker run -it -d --name openresty2 lihu12344/openresty
huli@hudeMacBook-Pro centos7 % docker exec -it openresty2 bash
# 命令存放位置
[root@6ff3ad5827e2 /]# cd /usr/local/openresty/bin
[root@6ff3ad5827e2 bin]# ls
md2pod.pl nginx-xml2pod openresty opm resty restydoc restydoc-index
# opm命令
[root@6ff3ad5827e2 bin]# opm -h
opm [options] command package...
Options:
-h
--help Print this help.
--install-dir=PATH Install into the specified PATH directory instead of the system-wide
OpenResty installation tree containing this tool.
--cwd Install into the current working directory under ./resty_modules/
instead of the system-wide OpenResty installation tree containing
this tool.
Commands:
build Build from the current working directory a package tarball ready
for uploading to the server.
clean ARGUMENT... Do clean-up work. Currently the valid argument is "dist", which
cleans up the temporary files and directories created by the "build"
command.
info PACKAGE... Output the detailed information (or meta data) about the specified
packages. Short package names like "lua-resty-lock" are acceptable.
get PACKAGE... Fetch and install the specified packages. Fully qualified package
names like "openresty/lua-resty-lock" are required. One can also
specify a version constraint like "=0.05" and ">=0.01".
list List all the installed packages. Both the package names and versions
are displayed.
remove PACKAGE... Remove (or uninstall) the specified packages. Short package names
like "lua-resty-lock" are acceptable.
search QUERY... Search on the server for packages matching the user queries in their
names or abstracts. Multiple queries can be specified and they must
fulfilled at the same time.
server-build Build a final package tarball ready for distribution on the server.
This command is usually used by the server to verify the uploaded
package tarball.
update Update all the installed packages to their latest version from
the server.
upgrade PACKAGE... Upgrade the packages specified by names to the latest version from
the server. Short package names like "lua-resty-lock" are acceptable.
upload Upload the package tarball to the server. This command always invokes
the build command automatically right before uploading.
For bug reporting instructions, please see:
<https://openresty.org/en/community.html>
Copyright (C) Yichun Zhang (agentzh). All rights reserved.
三方模块安装
huli@hudeMacBook-Pro ~ % docker exec -it openresty2 bash
[root@6ff3ad5827e2 /]# cd /usr/local/openresty/bin
[root@6ff3ad5827e2 bin]# ls
md2pod.pl nginx-xml2pod openresty opm resty restydoc restydoc-index
# 搜索模块
[root@6ff3ad5827e2 bin]# opm search lua-resty-jit-uuid
thibaultcha/lua-resty-jit-uuid Fast and dependency-free uuid generation for OpenResty/LuaJIT
# 安装模块:
[root@6ff3ad5827e2 bin]# opm install thibaultcha/lua-resty-jit-uuid
* Fetching thibaultcha/lua-resty-jit-uuid
Downloading https://opm.openresty.org/api/pkg/tarball/thibaultcha/lua-resty-jit-uuid-0.0.7.opm.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6398 100 6398 0 0 17058 0 --:--:-- --:--:-- --:--:-- 17106
Package thibaultcha/lua-resty-jit-uuid 0.0.7 installed successfully under /usr/local/openresty/site/ .
# 查看安装的模块
[root@6ff3ad5827e2 bin]# opm list
thibaultcha/lua-resty-jit-uuid 0.0.7
# 全局模块安装目录
[root@6ff3ad5827e2 site]# cd /usr/local/openresty/site/lualib/resty
[root@6ff3ad5827e2 resty]# ls
jit-uuid.lua
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
init_worker_by_lua_block { //初始化
local uuid = require 'resty.jit-uuid';
uuid.seed();
}
server {
location /lua { //ngx输出
default_type "applictaion/json";
content_by_lua "ngx.say('hello gtlx')";
}
location /uuid { //输出uuid字符串
content_by_lua_block {
local uuid = require 'resty.jit-uuid';
ngx.say(uuid());
}
}
}
client_body_temp_path /var/run/openresty/nginx-client-body;
proxy_temp_path /var/run/openresty/nginx-proxy;
fastcgi_temp_path /var/run/openresty/nginx-fastcgi;
uwsgi_temp_path /var/run/openresty/nginx-uwsgi;
scgi_temp_path /var/run/openresty/nginx-scgi;
sendfile on;
keepalive_timeout 65;
}
docker run -it -d -p 8081:80 \
-v /Users/huli/lua/openresty/conf/nginx.conf:/usr/local/openresty/nginx /conf/nginx.conf \
--name openresty2 lihu12344/openresty
huli@hudeMacBook-Pro ~ % docker exec -it openresty2 bash
[root@201c0651d209 bin]# cd /usr/local/openresty/bin
[root@201c0651d209 bin]# ls
md2pod.pl nginx-xml2pod openresty opm resty restydoc restydoc-index
# 查找模块
[root@201c0651d209 bin]# opm search lua-resty-jit-uuid
thibaultcha/lua-resty-jit-uuid Fast and dependency-free uuid generation for OpenResty/LuaJIT
# 安装模块
[root@201c0651d209 bin]# opm install thibaultcha/lua-resty-jit-uuid
Package lua-resty-jit-uuid-0.0.7 already installed.
# ngx_lua
huli@hudeMacBook-Pro openresty % curl localhost:8081/lua
hello gtlx
# lua-resty-jit-uuid
huli@hudeMacBook-Pro openresty % curl localhost:8081/uuid
8bc6e561-6b9c-4fdf-9569-2814d2180b1f