Sign inSign up

prantlf/nginx-lua-openresty

By prantlf

•Updated about 6 years ago

Nginx for web applications written in Lua on Alpine Linux

Image
0

555

prantlf/nginx-lua-openresty repository overview

⁠prantlf/nginx-lua-openresty

Docker⁠ image: Nginx for web applications written in Lua on Alpine Linux

prantlf/nginx-lua-openresty

This image⁠ is supposed to run web applications using static assets and dynamic requests coded in [Lua] or as Lua Pages⁠. This image is built automatically on the top of the tag latest from the Alpine repository⁠, so that it is always based on the latest Alpine Linux⁠. Packages openresty⁠, libuuid and tzdata have to be updated from time to time by triggering a new build manually.

Additional Lua packages included:

⁠Tags

⁠Install

docker pull prantlf/nginx-lua-openresty

⁠Use

You can serve a web application consisting of both Lua Pages⁠ and static assets:

cd ~/my-web-application
docker run --rm -it -p 80:80 -v "${PWD}/www":/app nginx-lua-openresty

You can add locations to server2.conf to serve REST API or other dynamic content. If you need a global initialization code, you can add it to a file included in the http context. Then you need to pass the files to the container as volumes:

cd ~/my-web-application
docker run --rm -it -p 80:80 -v "${PWD}/www":/app \
  -v "${PWD}/conf/http2.conf":/usr/local/openresty/nginx/conf/http2.conf
  -v "${PWD}/conf/server2.conf":/usr/local/openresty/nginx/conf/server2.conf \
  nginx-lua-openresty

Default content of http2.conf:

init_by_lua_block {
  template = require "resty.template"
}

Default content of server2.conf:

location ~ ^(.+\.lsp)(?:\?[^?]*)?$ {
  default_type text/html;
  set $page $1;
  content_by_lua_block {
    local template = require "resty.template"
    template.render_file(ngx.var.page)
  }
}

This image allows adding custom configuration to three Nginx contexts by replacing three files using volumes:

/usr/local/openresty/nginx/conf/nginx2.conf  - main
/usr/local/openresty/nginx/conf/http2.conf   - http
/usr/local/openresty/nginx/conf/server2.conf - server

You can replace the whole default configuration or its part by using volumes too:

/usr/local/openresty/nginx/conf/nginx.conf  - the whole configuration
/usr/local/openresty/nginx/conf/http.conf   - the http section
/usr/local/openresty/nginx/conf/server.conf - the server section

⁠Build, Test and Publish

The local image is built as nginx-lua-openresty and pushed to the docker hub as prantlf/nginx-lua-openresty:latest.

Remove an old local image:

make clean

Check the Dockerfile:

make lint

Build a new local image:

make build

Enter an interactive shell inside the created image:

make run

Test a default web application:

make serve

Test a customized web application:

make example

Tag the local image for pushing:

make tag

Login to the docker hub:

make login

Push the local image to the docker hub:

make push

⁠License

Copyright (c) 2020 Ferdinand Prantl

Licensed under the MIT license.

Tag summary

Content type

Image

Digest

Size

7.5 MB

Last updated

about 6 years ago

docker pull prantlf/nginx-lua-openresty