Last active
October 20, 2015 04:00
-
-
Save caevyn/7892aa4ed0b1b2e0831b to your computer and use it in GitHub Desktop.
docker openresty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile for openresty | |
FROM centos:7 | |
MAINTAINER matt murphy | |
ENV http_proxy http://10.0.2.2:3128/ | |
ENV https_proxy https://10.0.2.2:3128/ | |
ENV PKG ngx_openresty-${openresty_version:-"1.7.10.1"} | |
RUN yum install -y readline-devel pcre-devel openssl-devel gcc wget perl make | |
RUN wget http://openresty.org/download/${PKG}.tar.gz \ | |
&& wget http://openresty.org/download/${PKG}.tar.gz.asc \ | |
&& gpg --keyserver pgpkeys.mit.edu --recv-key A0E98066 \ | |
&& gpg --fingerprint A0E98066 \ | |
&& gpg --verify ${PKG}.tar.gz.asc ${PKG}.tar.gz \ | |
&& tar xzvf ${PKG}.tar.gz | |
RUN cd ${PKG} \ | |
&& ./configure --with-pcre-jit \ | |
--with-ipv6 \ | |
&& make \ | |
&& make install | |
RUN rm /usr/local/openresty/nginx/conf/nginx.conf | |
ADD nginx.conf /usr/local/openresty/nginx/conf/nginx.conf | |
ADD myapp /usr/local/openresty/lualib/myapp | |
CMD /usr/local/openresty/nginx/sbin/nginx | |
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
error_log stderr notice; | |
daemon off; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
variables_hash_max_size 1024; | |
access_log off; | |
include /usr/local/openresty/nginx/conf/mime.types; | |
charset utf-8; | |
init_by_lua ' | |
require "resty.core" | |
'; | |
resolver 8.8.8.8; | |
default_type text/html; | |
server { | |
listen 80; | |
lua_code_cache off; | |
location / { | |
set $proxy_to ""; | |
rewrite_by_lua ' | |
local app = require "myapp.stuff" | |
local proxy_to = app.proxy_map(ngx.var.uri) | |
if proxy_to == nil then | |
app.say_hi("dude") | |
end | |
ngx.var.proxy_to = proxy_to; | |
'; | |
proxy_pass $proxy_to; | |
} | |
location /dude/ { | |
content_by_lua ' | |
local app = require "myapp.stuff" | |
app.say_hi("dude") | |
'; | |
} | |
location /static/ { | |
alias static/; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_M = {} | |
local proxy_map = { | |
["/google"]="http://www.google.com.au/", | |
["/cats"]="http://www.catsthemusical.com/" | |
} | |
function _M.say_hi(name) | |
local hi = 'Hello ' .. name | |
ngx.say(hi) | |
ngx.exit(200) | |
end | |
function _M.proxy_map(path) | |
return proxy_map[path] | |
end | |
return _M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment