Skip to content

Commit

Permalink
增加webjars 的bootstrap and jquery ;
Browse files Browse the repository at this point in the history
nginx 缓存webjars 配置;
  • Loading branch information
supermy committed Jun 16, 2015
1 parent f4471b3 commit 8495938
Show file tree
Hide file tree
Showing 33 changed files with 766 additions and 34 deletions.
2 changes: 1 addition & 1 deletion web+app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nginx(tengine)+tomcat+mysql+memcached 集群

> nginx 整合HttpRedis2Module/lua-resty-redis完成,http方式访问redis;
> mysql2redis.sh 将mysql 的数据同步到redis,通过linux 的crontab 进行配置;
>
> 增加webjars and nginx4webjars 缓存配置
>
>开发调试脚本
>
Expand Down
8 changes: 4 additions & 4 deletions web+app/fig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ data:
image: busybox
command: /bin/true
volumes:
- /Users/moyong/docker-share/www/:/data/www/
- /Users/moyong/project/env-myopensource/3-tools/mytools/web+app/mynginx/www:/data/www/
- /Users/moyong/docker-share/logs/web/:/usr/local/nginx/logs/
- /Users/moyong/docker-share/conf/nginx/lua/:/usr/local/nginx/conf/nginx.d/lua/ #配置文件,fix.me

- /Users/moyong/project/env-myopensource/3-tools/mytools/web+app/mynginx/nginx.d/lua/:/usr/local/nginx/conf/nginx.d/lua/ #配置文件,fix.me

#/Users/moyong/docker-share/app/ 覆盖了管理目录导致,导致管理功能不可用
data4app:
image: busybox
command: /bin/true
volumes:
- /Users/moyong/docker-share/app/:/tomcat/webapps/
# - /Users/moyong/docker-share/app/:/tomcat/webapps/
- /Users/moyong/docker-share/logs/app/:/tomcat/logs/


Expand Down
2 changes: 0 additions & 2 deletions web+app/init.sql

This file was deleted.

15 changes: 12 additions & 3 deletions web+app/mynginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ RUN make linux && make install
WORKDIR /tmp
RUN wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
RUN wget http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
RUN wget -e "http_proxy=http://10.77.45.191:8087" http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
#
RUN wget -e "http_proxy=http://172.16.70.18:8087" http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
RUN wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz


# mysql depends bit ,不兼容lua-5.3.0 ,兼容lua-5.2.0
RUN wget http://bitop.luajit.org/download/LuaBitOp-1.0.2.tar.gz
RUN wget -e "http_proxy=http://172.16.70.18:8087" http://bitop.luajit.org/download/LuaBitOp-1.0.2.tar.gz

RUN tar zxf LuaJIT-2.0.4.tar.gz
RUN tar zxf lua-cjson-2.1.0.tar.gz
RUN tar zxf ngx_openresty-1.7.10.1.tar.gz
RUN tar zxf LuaBitOp-1.0.2.tar.gz
RUN tar zxf ngx_cache_purge-2.3.tar.gz


WORKDIR /tmp/LuaJIT-2.0.4
Expand Down Expand Up @@ -93,6 +95,7 @@ RUN \
--add-module=/tmp/ngx_openresty-1.7.10.1/bundle/set-misc-nginx-module-0.28/ \
--add-module=/tmp/ngx_openresty-1.7.10.1/bundle/echo-nginx-module-0.57/ \
--add-module=/tmp/ngx_openresty-1.7.10.1/bundle/ngx_lua-0.9.15/ \
--add-module=/tmp/ngx_cache_purge-2.3/ \
&& make && make install


Expand All @@ -113,6 +116,12 @@ RUN chmod 755 /etc/my_init.d/nginx.sh

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir -p /var/lib/nginx/cache

#配置时区
RUN echo "Asia/Shanghai" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

EXPOSE 80 443

CMD ["/etc/my_init.d/nginx.sh"]
Expand Down
2 changes: 1 addition & 1 deletion web+app/mynginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ nginx(tengine)+tomcat+mysql+memcached 集群
> 渠道认证完成,部署的时候需要手动更改redis 的IP 地址。todo
> 升级lua由5.1.5 到5.3.0,支持goto ;相关插件升级到最新版本
> 语法校验 http://www.lua.org/demo.html
>
> webjars+nginx 缓存配置
>
> ## end
4 changes: 2 additions & 2 deletions web+app/mynginx/fig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ data:
image: busybox
command: /bin/true
volumes:
- /Users/moyong/docker-share/www/:/data/www/
- /Users/moyong/project/env-myopensource/3-tools/mytools/web+app/mynginx/www:/data/www/
- /Users/moyong/docker-share/logs/web/:/usr/local/nginx/logs/
- /Users/moyong/docker-share/conf/nginx/lua/:/usr/local/nginx/conf/nginx.d/lua/ #配置文件,fix.me
- /Users/moyong/project/env-myopensource/3-tools/mytools/web+app/mynginx/nginx.d/lua/:/usr/local/nginx/conf/nginx.d/lua/ #配置文件,fix.me

myredis:
image: redis:latest
Expand Down
39 changes: 39 additions & 0 deletions web+app/mynginx/nginx.d/lua.conf
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,42 @@ location = /old_mvd {
location = /proxy {

}

#first match ngx location
set $template_location "/templates";
#then match root read file
set $template_root "/usr/local/nginx/conf/nginx.d/lua/templates";

location /templates {
internal;
alias /usr/local/nginx/conf/nginx.d/lua/templates2;
}


#模板引擎
location /lua_template {
default_type 'text/html';
content_by_lua_file /usr/local/nginx/conf/nginx.d/lua/test_template.lua;
}


location /lua_template_1 {
default_type 'text/html';
content_by_lua_file /usr/local/nginx/conf/nginx.d/lua/test_template_1.lua;
}

location /lua_template_2 {
default_type 'text/html';
content_by_lua_file /usr/local/nginx/conf/nginx.d/lua/test_template_2.lua;
}

location /lua_template_3 {
default_type 'text/html';
content_by_lua_file /usr/local/nginx/conf/nginx.d/lua/test_template_3.lua;
}


location /test_template_view_layouts {
default_type 'text/html';
content_by_lua_file /usr/local/nginx/conf/nginx.d/lua/test_template_view_layouts.lua;
}
50 changes: 50 additions & 0 deletions web+app/mynginx/nginx.d/lua/resty/html/html.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
local template = require "resty.template"
local escape = template.escape
local concat = table.concat
local pairs = pairs
local type = type

local function tag(name, content, attr)
local r, a, content = {}, {}, content or attr
r[#r + 1] = "<"
r[#r + 1] = name
if attr then
for k, v in pairs(attr) do
if type(k) == "number" then
a[#a + 1] = escape(v)
else
a[#a + 1] = k .. '="' .. escape(v) .. '"'
end
end
if #a > 0 then
r[#r + 1] = " "
r[#r + 1] = concat(a, " ")
end
end
if type(content) == "string" then
r[#r + 1] = ">"
r[#r + 1] = escape(content)
r[#r + 1] = "</"
r[#r + 1] = name
r[#r + 1] = ">"
else
r[#r + 1] = " />"
end
return concat(r)
end

local html = { __index = function(_, name)
return function(attr)
if type(attr) == "table" then
return function(content)
return tag(name, content, attr)
end
else
return tag(name, attr)
end
end
end }

template.html = setmetatable(html, html)

return template.html
121 changes: 121 additions & 0 deletions web+app/mynginx/nginx.d/lua/resty/html/microbenchmark.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
local template = require "resty.template"

local ok, new_tab = pcall(require, "table.new")
if not ok then
new_tab = function (narr, nrec) return {} end
end

local function run(iterations)
local total, print, parse, compile, iterations, clock = 0, ngx and ngx.say or print, template.parse, template.compile, iterations or 1000, os.clock

local view = [[
<ul>
{% for _, v in ipairs(context) do %}
<li>{{v}}</li>
{% end %}
</ul>]]

print(string.format("Running %d iterations in each test", iterations))

local x = clock()
for i = 1, iterations do
parse(view, true)
end
local z = clock() - x
print(string.format(" Parsing Time: %.6f", z))
total = total + z

x = clock()
for i = 1, iterations do
compile(view, nil, true)
template.cache = {}
end
z = clock() - x
print(string.format("Compilation Time: %.6f (template)", z))
total = total + z

compile(view, nil, true)

x = clock()
for i = 1, iterations do
compile(view, 1, true)
end
z = clock() - x
print(string.format("Compilation Time: %.6f (template cached)", z))
total = total + z

local context = { "Emma", "James", "Nicholas", "Mary" }

template.cache = {}

x = clock()
for i = 1, iterations do
compile(view, 1, true)(context)
template.cache = {}
end
z = clock() - x
print(string.format(" Execution Time: %.6f (same template)", z))
total = total + z

template.cache = {}
compile(view, 1, true)

x = clock()
for i = 1, iterations do
compile(view, 1, true)(context)
end
z = clock() - x
print(string.format(" Execution Time: %.6f (same template cached)", z))
total = total + z

template.cache = {}

local views = new_tab(iterations, 0)
for i = 1, iterations do
views[i] = "<h1>Iteration " .. i .. "</h1>\n" .. view
end

x = clock()
for i = 1, iterations do
compile(views[i], i, true)(context)
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template)", z))
total = total + z

x = clock()
for i = 1, iterations do
compile(views[i], i, true)(context)
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template cached)", z))
total = total + z

template.cache = {}
local contexts = new_tab(iterations, 0)

for i = 1, iterations do
contexts[i] = {"Emma " .. i, "James " .. i, "Nicholas " .. i, "Mary " .. i }
end

x = clock()
for i = 1, iterations do
compile(views[i], i, true)(contexts[i])
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template, different context)", z))
total = total + z

x = clock()
for i = 1, iterations do
compile(views[i], i, true)(contexts[i])
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template, different context cached)", z))
total = total + z
print(string.format(" Total Time: %.6f", total))
end

return {
run = run
}
Loading

0 comments on commit 8495938

Please sign in to comment.