Saki's 研究记录

docker-compose部署openresty

字数统计: 488阅读时长: 2 min
2021/11/11

简介

OpenResty 可以直接使用 Lua 脚本编写复杂的逻辑运行在 Nginx 之上,可以做很多好玩的应用,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。
环境:
机型: 1核 1GB 1Mbps 腾讯云服务器
系统: CentOS Linux release 8.4.2105 (Core)

部署步骤

  1. 创建挂载目录

    1
    mkdir -p openresty
  2. 编写 docker-compose.yaml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    version: '3'
    services:
    openresty:
    image: openresty/openresty:alpine
    restart: always
    volumes:
    #- $PWD/conf:/usr/local/openresty/nginx/conf
    #- $PWD/logs:/usr/local/openresty/nginx/logs
    - /etc/localtime:/etc/localtime
    networks:
    - openresty-network
    ports:
    - "80:80"

    networks:
    openresty-network:
    driver: bridge
  3. 启动openresty

    1
    docker-compose up -d
  4. 将容器内的初始配置拷贝

    1
    2
    docker cp openresty_openresty_1:/usr/local/openresty/nginx/conf .
    docker cp openresty_openresty_1:/usr/local/openresty/nginx/logs .
  5. 删除 openresty 容器

    1
    docker-compose down
  6. 去掉注释以挂载方式启动

    1
    docker-compose up -d
  7. 测试是否成功

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    curl 127.0.0.1:80

    <!DOCTYPE html>
    <html>
    <head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <title>Welcome to OpenResty!</title>
    <style>
    body {
    width: 35em;
    margin: 0 auto;
    font-family: Tahoma, Verdana, Arial, sans-serif;
    }
    </style>
    </head>
    <body>
    <h1>Welcome to OpenResty!</h1>
    <p>If you see this page, the OpenResty web platform is successfully installed and
    working. Further configuration is required.</p>

    <p>For online documentation and support please refer to our
    <a href="https://openresty.org/">openresty.org</a> site<br/>
    Commercial support is available at
    <a href="https://openresty.com/">openresty.com</a>.</p>
    <p>We have articles on troubleshooting issues like <a href="https://blog.openresty.com/en/lua-cpu-flame-graph/?src=wb">high CPU usage</a> and
    <a href="https://blog.openresty.com/en/how-or-alloc-mem/">large memory usage</a> on <a href="https://blog.openresty.com/">our official blog site</a>.
    <p><em>Thank you for flying <a href="https://openresty.org/">OpenResty</a>.</em></p>
    </body>
    </html>

Done.

CATALOG
  1. 1. 简介
  2. 2. 部署步骤