├── .gitignore ├── Dockerfile ├── README.md ├── build.sh ├── images ├── docker.png └── github.png └── nginx.conf /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.orig 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Based on manual compile instructions at http://wiki.nginx.org/HttpLuaModule#Installation 2 | FROM ubuntu:14.04 3 | 4 | ENV VER_NGINX_DEVEL_KIT=0.2.19 5 | ENV VER_LUA_NGINX_MODULE=0.9.16 6 | ENV VER_NGINX=1.7.10 7 | ENV VER_LUAJIT=2.0.4 8 | 9 | ENV NGINX_DEVEL_KIT ngx_devel_kit-${VER_NGINX_DEVEL_KIT} 10 | ENV LUA_NGINX_MODULE lua-nginx-module-${VER_LUA_NGINX_MODULE} 11 | ENV NGINX_ROOT=/nginx 12 | ENV WEB_DIR ${NGINX_ROOT}/html 13 | 14 | ENV LUAJIT_LIB /usr/local/lib 15 | ENV LUAJIT_INC /usr/local/include/luajit-2.0 16 | 17 | RUN apt-get -qq update 18 | RUN apt-get -qq -y install wget 19 | 20 | # ***** BUILD DEPENDENCIES ***** 21 | 22 | # Common dependencies (Nginx and LUAJit) 23 | RUN apt-get -qq -y install make 24 | # Nginx dependencies 25 | RUN apt-get -qq -y install libpcre3 26 | RUN apt-get -qq -y install libpcre3-dev 27 | RUN apt-get -qq -y install zlib1g-dev 28 | RUN apt-get -qq -y install libssl-dev 29 | # LUAJit dependencies 30 | RUN apt-get -qq -y install gcc 31 | 32 | # ***** DOWNLOAD AND UNTAR ***** 33 | 34 | # Download 35 | RUN wget http://nginx.org/download/nginx-${VER_NGINX}.tar.gz 36 | RUN wget http://luajit.org/download/LuaJIT-${VER_LUAJIT}.tar.gz 37 | RUN wget https://github.com/simpl/ngx_devel_kit/archive/v${VER_NGINX_DEVEL_KIT}.tar.gz -O ${NGINX_DEVEL_KIT}.tar.gz 38 | RUN wget https://github.com/openresty/lua-nginx-module/archive/v${VER_LUA_NGINX_MODULE}.tar.gz -O ${LUA_NGINX_MODULE}.tar.gz 39 | # Untar 40 | RUN tar -xzvf nginx-${VER_NGINX}.tar.gz && rm nginx-${VER_NGINX}.tar.gz 41 | RUN tar -xzvf LuaJIT-${VER_LUAJIT}.tar.gz && rm LuaJIT-${VER_LUAJIT}.tar.gz 42 | RUN tar -xzvf ${NGINX_DEVEL_KIT}.tar.gz && rm ${NGINX_DEVEL_KIT}.tar.gz 43 | RUN tar -xzvf ${LUA_NGINX_MODULE}.tar.gz && rm ${LUA_NGINX_MODULE}.tar.gz 44 | 45 | # ***** BUILD FROM SOURCE ***** 46 | 47 | # LuaJIT 48 | WORKDIR /LuaJIT-${VER_LUAJIT} 49 | RUN make 50 | RUN make install 51 | # Nginx with LuaJIT 52 | WORKDIR /nginx-${VER_NGINX} 53 | RUN ./configure --prefix=${NGINX_ROOT} --with-ld-opt="-Wl,-rpath,${LUAJIT_LIB}" --add-module=/${NGINX_DEVEL_KIT} --add-module=/${LUA_NGINX_MODULE} 54 | RUN make -j2 55 | RUN make install 56 | RUN ln -s ${NGINX_ROOT}/sbin/nginx /usr/local/sbin/nginx 57 | 58 | # ***** MISC ***** 59 | WORKDIR ${WEB_DIR} 60 | EXPOSE 80 61 | EXPOSE 443 62 | 63 | # ***** CLEANUP ***** 64 | RUN rm -rf /nginx-${VER_NGINX} 65 | RUN rm -rf /LuaJIT-${VER_LUAJIT} 66 | RUN rm -rf /${NGINX_DEVEL_KIT} 67 | RUN rm -rf /${LUA_NGINX_MODULE} 68 | # TODO: Uninstall build only dependencies? 69 | # TODO: Remove env vars used only for build? 70 | 71 | # This is the default CMD used by nginx:1.9.2 image 72 | CMD ["nginx", "-g", "daemon off;"] 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nginx-lua 2 | ========= 3 | 4 | ![Docker stars](https://img.shields.io/docker/stars/danday74/nginx-lua.png "Docker stars") 5 |   6 | ![Docker pulls](https://img.shields.io/docker/pulls/danday74/nginx-lua.png "Docker pulls") 7 | 8 | [![Docker repo](https://github.com/danday74/docker-nginx-lua/blob/master/images/docker.png?raw=true "Docker repo")](https://registry.hub.docker.com/u/danday74/nginx-lua) 9 |   10 | [![Github repo](https://github.com/danday74/docker-nginx-lua/blob/master/images/github.png?raw=true "Github repo")](https://github.com/danday74/docker-nginx-lua) 11 | 12 | Dockerised Nginx, with Lua module, built from source 13 | 14 | The docker image is based on the manual compilation instructions at ... 15 | 16 | [http://wiki.nginx.org/HttpLuaModule#Installation](http://wiki.nginx.org/HttpLuaModule#Installation) 17 | 18 | Useful for those who want Nginx with Lua but don't want to use OpenResty 19 | 20 | Usage 21 | ----- 22 | 23 | 1. Create your own **Dockerfile** ... 24 | 25 | ``` 26 | FROM danday74/nginx-lua 27 | COPY /your/nginx.conf /nginx/conf/nginx.conf 28 | ``` 29 | 30 | 2. Add this location block to your **nginx.conf** file 31 | 32 | ``` 33 | location /hellolua { 34 | content_by_lua ' 35 | ngx.header["Content-Type"] = "text/plain"; 36 | ngx.say("hello world"); 37 | '; 38 | } 39 | ``` 40 | 41 | If you don't have an **nginx.conf** file then use [the conf file](https://raw.githubusercontent.com/danday74/docker-nginx-lua/master/nginx.conf) provided in the github repo 42 | 43 | The conf file provided is the default generated conf file with the above location block added 44 | 45 | 3. Build your docker image 46 | 47 | 4. Run your docker container - Remember to use **-p YOUR_PORT:80** in your docker run statement 48 | 49 | 5. Visit http://localhost:YOUR_PORT/hellolua 50 | 51 | Automated 52 | --------- 53 | 54 | The master branch on the github repo is watched by an automated docker build 55 | 56 | Which builds docker image **danday74/nginx-lua** on push to master 57 | 58 | On success, the docker build triggers the docker repo's webhooks (if any) 59 | 60 | License 61 | ------- 62 | 63 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 64 | 65 | APACHE LICENSE-2.0 ... In other words, please use freely and do whatever you want with it! 66 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | docker build -t "danday74/nginx-lua" . 2 | -------------------------------------------------------------------------------- /images/docker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danday74/docker-nginx-lua/121e4e21357be09e9b96cb406e9b86dfde6cab16/images/docker.png -------------------------------------------------------------------------------- /images/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danday74/docker-nginx-lua/121e4e21357be09e9b96cb406e9b86dfde6cab16/images/github.png -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | #user nobody; 2 | worker_processes 1; 3 | 4 | #error_log logs/error.log; 5 | #error_log logs/error.log notice; 6 | #error_log logs/error.log info; 7 | 8 | #pid logs/nginx.pid; 9 | 10 | events { 11 | worker_connections 1024; 12 | } 13 | 14 | http { 15 | include mime.types; 16 | default_type application/octet-stream; 17 | 18 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | # '$status $body_bytes_sent "$http_referer" ' 20 | # '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | #access_log logs/access.log main; 23 | 24 | sendfile on; 25 | #tcp_nopush on; 26 | 27 | #keepalive_timeout 0; 28 | keepalive_timeout 65; 29 | 30 | #gzip on; 31 | 32 | server { 33 | listen 80; 34 | server_name localhost; 35 | 36 | #charset koi8-r; 37 | 38 | #access_log logs/host.access.log main; 39 | 40 | location / { 41 | root html; 42 | index index.html index.htm; 43 | } 44 | 45 | location /hellolua { 46 | content_by_lua ' 47 | ngx.header["Content-Type"] = "text/plain"; 48 | ngx.say("hello world"); 49 | '; 50 | } 51 | 52 | #error_page 404 /404.html; 53 | 54 | # redirect server error pages to the static page /50x.html 55 | # 56 | error_page 500 502 503 504 /50x.html; 57 | location = /50x.html { 58 | root html; 59 | } 60 | 61 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 62 | # 63 | #location ~ \.php$ { 64 | # proxy_pass http://127.0.0.1; 65 | #} 66 | 67 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 68 | # 69 | #location ~ \.php$ { 70 | # root html; 71 | # fastcgi_pass 127.0.0.1:9000; 72 | # fastcgi_index index.php; 73 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 74 | # include fastcgi_params; 75 | #} 76 | 77 | # deny access to .htaccess files, if Apache's document root 78 | # concurs with nginx's one 79 | # 80 | #location ~ /\.ht { 81 | # deny all; 82 | #} 83 | } 84 | 85 | # another virtual host using mix of IP-, name-, and port-based configuration 86 | # 87 | #server { 88 | # listen 8000; 89 | # listen somename:8080; 90 | # server_name somename alias another.alias; 91 | 92 | # location / { 93 | # root html; 94 | # index index.html index.htm; 95 | # } 96 | #} 97 | 98 | # HTTPS server 99 | # 100 | #server { 101 | # listen 443 ssl; 102 | # server_name localhost; 103 | 104 | # ssl_certificate cert.pem; 105 | # ssl_certificate_key cert.key; 106 | 107 | # ssl_session_cache shared:SSL:1m; 108 | # ssl_session_timeout 5m; 109 | 110 | # ssl_ciphers HIGH:!aNULL:!MD5; 111 | # ssl_prefer_server_ciphers on; 112 | 113 | # location / { 114 | # root html; 115 | # index index.html index.htm; 116 | # } 117 | #} 118 | } 119 | --------------------------------------------------------------------------------