美文网首页
Docker 安装OpenResty

Docker 安装OpenResty

作者: iOS虞 | 来源:发表于2023-11-20 08:33 被阅读0次

拉取镜像

docker pull openresty/openresty

启动

docker run --name openresty \
-p 80:80 \
-d openresty/openresty

挂载目录

  1. 创建宿主机目录
mkdir -p /software/docker/openresty/conf
mkdir -p /software/docker/openresty/html
mkdir -p /software/docker/openresty/lua

2.拷贝容器中文件到宿主机目录

//拷贝nginx配置文件
docker cp openresty:/usr/local/openresty/nginx/conf/nginx.conf /software/docker/openresty/conf
//拷贝lua库
docker cp openresty:/usr/local/openresty/lualib /software/docker/openresty/

删除容器,重新启动一个新的容器

//删除容器
docker rm -f openresty

//启动
docker run --name openresty \
-v /software/docker/openresty/conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \
-v /software/docker/openresty/lua/:/usr/local/openresty/nginx/lua \
-v /software/docker/openresty/lualib/:/usr/local/openresty/lualib \
-v /software/docker/openresty/html/:/usr/local/openresty/nginx/html \
-p 80:80 -d openresty/openresty

测试lua模块

  1. 在宿主机/software/docker/openresty/lua目录中创建test.lua
vim test.lua
ngx.say('{"id" : "10086", "name":"test"}')
  1. 修改配置文件nginx.conf

http {
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;
    underscores_in_headers on;#表示如果header name中包含下划线,则不忽略

    sendfile        on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;
    #include /etc/nginx/conf.d/*.conf;
    #lua 模块
    lua_package_path "/usr/local/openresty/lualib/?.lua;;";
    #c模块     
    lua_package_cpath "/usr/local/openresty/lualib/?.so;;";  
    server {
        listen       80;
        server_name  127.0.0.1;
        location /test {
            # 默认的响应类型
            default_type application/json;
            content_by_lua_file lua/test.lua;
        }
        
        location / {
            root   html;
            index  index.html index.htm;
        }
   }
}
  1. 测试

10.211.55.6/test

相关文章

网友评论

      本文标题:Docker 安装OpenResty

      本文链接:https://www.haomeiwen.com/subject/ekqvwdtx.html