[关闭]
@1234567890 2017-05-22T13:23:33.000000Z 字数 1940 阅读 1419

nginx+lua

nginx


安装

  1. wget https://openresty.org/download/openresty-1.11.2.1.tar.gz
  2. tar -xzvf openresty-1.11.2.1.tar.gz
  3. //安装LuaJIT
  4. cd bundle/LuaJIT-2.1-20150120/
  5. make clean && make && make install
  6. ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
  7. //openresty-1.11.2.1/bundle目录下
  8. //下载ngx_cache_purge模块,该模块用于清理nginx缓存
  9. wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
  10. tar -xvf 2.3.tar.gz
  11. //openresty-1.11.2.1/bundle目录下
  12. //下载nginx_upstream_check_module模块,该模块用于ustream健康检查
  13. wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
  14. tar -xvf v0.3.0.tar.gz
  15. //openresty-1.11.2.1目录下
  16. ./configure --prefix=/usr/servers --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/
  17. make -j2
  18. make install

参考安装
碰到问题
1. ./configure: error: SSL modules require the OpenSSL library.

解决yum -y install openssl openssl-devel

  1. ./configure --prefix=/usr/servers --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2
  2. make && make install
  3. --with*** 安装一些内置/集成的模块
  4. --with-http_realip_module 取用户真实ip模块
  5. -with-pcre Perl兼容的达式模块
  6. --with-luajit 集成luajit模块
  7. --add-module 添加自定义的第三方模块,如此次的ngx_che_purge

nginx+lua

目录

  1. example
  2. example.conf ---该项目的nginx 配置文件
  3. lua ---我们自己的lua代码
  4. test.lua
  5. lualib ---lua依赖库/第三方依赖
  6. *.lua
  7. *.so

nginx.conf

  1. #user nobody;
  2. worker_processes 2;
  3. error_log logs/error.log;
  4. events {
  5. worker_connections 1024;
  6. }
  7. http {
  8. include mime.types;
  9. default_type text/html;
  10. #lua模块路径,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找
  11. lua_package_path "/usr/example/lualib/?.lua;;"; #lua 模块
  12. lua_package_cpath "/usr/example/lualib/?.so;;"; #c模块
  13. include /usr/example/example.conf;
  14. }

example.conf

  1. server {
  2. listen 80;
  3. server_name _;
  4. location /lua {
  5. default_type 'text/html';
  6. lua_code_cache off;
  7. content_by_lua_file /usr/example/lua/test.lua;
  8. }
  9. }

默认情况下lua_code_cache是开启的,即缓存lua代码,即每次lua代码变更必须reload nginx才生效,如果在开发阶段可以通过lua_code_cache off;关闭缓存,这样调试时每次修改lua代码不需要reload nginx;但是正式环境一定记得开启缓存。

test.lua

  1. ngx.say("hello world");
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注