Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

configure finish,use : lua_file ...

  • Loading branch information...
commit 53952682e7121ef831cc5125715d641bf9c586ad 1 parent a5447d2
@alacner authored
View
11 README
@@ -1 +1,12 @@
+-- exapmle:
+ location ~/test {
+ lua_file "/usr/local/nginx/conf/test.lua";
+ }
+
+ location ~/lua {
+ lua_file "/usr/local/nginx/conf/lua.lua";
+ }
+
+
+
Tue Apr 26 16:30:00 MST 2011
View
58 example/t1.lua
@@ -0,0 +1,58 @@
+--Copyright (c) 2011-2015 Zhihua Zhang (alacner@gmail.com)
+ngx.set_header('Content-Type', "text");
+
+--local f = io.open('/root/test.jpg', 'rb')
+--ngx.print(f:read("*a"))
+print = ngx.print
+local kit = require("kit")
+local print_r = kit.print_r
+
+print_r(ngx)
+local http = require("socket.http")
+local r, e, h = http.request("http://www.6uu.com")
+print_r(h)
+ngx.set_header("Set-Cookie", 'love=xxx;');
+do return end
+--ngx.print(table.concat(p))
+--[[
+]]
+ngx.print('hhhhhhhhhhh')
+ngx.print('<br/>')
+ngx.print(ngx.random)
+ngx.print('<br/>')
+ngx.print(ngx.server.QUERY_STRING)
+print(os.time())
+local Flexihash = require "Flexihash"
+local flexihash = Flexihash.New()
+flexihash:addTarget('10.249.196.117|11211|0')
+flexihash:addTarget('10.249.196.118|11211|0')
+flexihash:addTarget('10.249.196.119|11211|0')
+flexihash:addTarget('10.249.196.120|11211|0')
+flexihash:addTarget('10.249.196.121|11211|0')
+flexihash:addTarget('10.249.196.122|11211|0')
+flexihash:addTarget('10.249.196.123|11211|0')
+flexihash:addTarget('10.249.196.123|11211|0')
+flexihash:addTarget('10.249.196.124|11211|0')
+print_r(flexihash:getAllTargets())
+local memcache_key = os.time();
+local config = flexihash:lookup(memcache_key)
+ngx.set_header('X-Memc-Flags', config);
+print(memcache_key, ' => ', config)
+print("\r\n memcached\r\n")
+
+--[=====[
+require "Memcached"
+--local memc = Memcached.New('127.0.0.1', 11211)
+--memc:set('1234', 1234)
+--print(memc:get(1234))
+
+local socket = require("socket")
+local sc = socket.connect('127.0.0.1', 11211)
+--local sc = socket.connect('10.249.196.117', 11211)
+sc:send("get " .. config .. "\r\n")
+local answer = sc:receive()
+print(answer)
+
+print_r(ngx)
+print"------ end -----"
+--]=====]
View
130 nginx.conf
@@ -1,130 +0,0 @@
-
-#user nobody;
-daemon off;
-worker_processes 1;
-master_process off;
-#error_log logs/error.log debug;
-#error_log logs/error.log;
-#error_log logs/error.log notice;
-#error_log logs/error.log info;
-
-#pid logs/nginx.pid;
-
-
-events {
- worker_connections 1024;
-}
-
-
-http {
- include mime.types;
- default_type application/octet-stream;
-
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
-
- #access_log logs/access.log main;
-
- sendfile on;
- #tcp_nopush on;
-
- #keepalive_timeout 0;
- keepalive_timeout 65;
-
- #gzip on;
-
- server {
- listen 80;
- server_name localhost;
- access_log /tmp/access.log;
- error_log /tmp/error.log debug;
-
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
-
- location / {
- root html;
- index index.html index.htm;
- }
-
-
-location =/lua {
-default_type 'text/plain';
-ngx_lua_module;
-lua "conf/lua_test.lua";
-}
-
-
- #error_page 404 /404.html;
-
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
-
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
-
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
-
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
-
-
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
-
- # HTTPS server
- #
- #server {
- # listen 443;
- # server_name localhost;
-
- # ssl on;
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
-
- # ssl_session_timeout 5m;
-
- # ssl_protocols SSLv2 SSLv3 TLSv1;
- # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
- # ssl_prefer_server_ciphers on;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
-}
View
14 src/ngx_http_lua_module.c
@@ -44,12 +44,10 @@ static ngx_int_t ngx_set_http_out_header(ngx_http_request_t *r, char *key, char
static ngx_int_t ngx_set_http_by_lua(ngx_http_request_t *r);
static void log_wrapper(ngx_http_request_t *r, const char *ident, int level, lua_State *L);
-static char g_foo_settings[64] = {0};
-
static int luaM_print (lua_State *L);
static int luaM_set_header (lua_State *L);
-static int luaM_get_get (lua_State *L);
#if 0
+static int luaM_get_get (lua_State *L);
static int luaM_get_request (lua_State *L);
static int luaM_get_post (lua_State *L);
@@ -122,7 +120,7 @@ static ngx_http_module_t ngx_http_lua_module_ctx = {
NULL, /* create server configuration */
NULL, /* merge server configuration */
- ngx_http_lua_create_loc_conf, /* create location configuration */
+ ngx_http_lua_create_loc_conf, /* create location configuration */
NULL /* merge location configuration */
};
@@ -264,9 +262,6 @@ static ngx_int_t ngx_set_http_by_lua(ngx_http_request_t *r){
lua_newtable(L); /* ngx */
- lua_pushstring(L, llcf->file_src.data);
- lua_setfield(L, -2, "script_path");
-
lua_pushnumber(L, ngx_random());
lua_setfield(L, -2, "random");
@@ -279,6 +274,9 @@ static ngx_int_t ngx_set_http_by_lua(ngx_http_request_t *r){
/* {{{ ngx.server */
lua_newtable(L);
+ lua_pushlstring(L, (const char *)llcf->file_src.data, llcf->file_src.len);
+ lua_setfield(L, -2, "SCRIPT_FILENAME");
+
lua_pushlstring(L, (const char *)r->uri.data, r->uri.len);
lua_setfield(L, -2, "REQUEST_URI");
@@ -330,7 +328,7 @@ static ngx_int_t ngx_set_http_by_lua(ngx_http_request_t *r){
lua_setglobal(L, "ngx");
// execute lua code
- if (luaL_dofile(L, "/usr/local/nginx/conf/test.lua") != 0) {
+ if (luaL_dofile(L, (const char *)llcf->file_src.data) != 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"runtime error: %s", lua_tostring(L, -1));
lua_pop(L, 1);
View
34 test.lua
@@ -1,34 +0,0 @@
--- Copyright (C) Alacner
---package.path = package.path .. '/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/core.lua;;'
---package.cpath = package.cpath .. '/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?/core.so;;';
-
-require "print_r"
-local nix = require ("nix")
-print_r(os.time())
-print_r(package.preload)
-print_r(require)
-print_r(nix.crc32(22))
-
-
-
-local socket = require("socket")
-local sc = socket.connect('10.249.196.117', 11211)
-sc:send("get 1234\r\n")
-local answer = sc:receive()
-print(answer)
-
-
-local Flexihash = require "Flexihash"
-local flexihash = Flexihash.New()
-flexihash:addTarget('10.249.196.117|11211|0')
-flexihash:addTarget('10.249.196.118|11211|0')
-flexihash:addTarget('10.249.196.119|11211|0')
-flexihash:addTarget('10.249.196.120|11211|0')
-flexihash:addTarget('10.249.196.121|11211|0')
-flexihash:addTarget('10.249.196.122|11211|0')
-flexihash:addTarget('10.249.196.123|11211|0')
-flexihash:addTarget('10.249.196.123|11211|0')
-flexihash:addTarget('10.249.196.124|11211|0')
-local memcache_key = os.time();
-local config = flexihash:lookup(memcache_key)
-print(memcache_key, ' => ', config)
Please sign in to comment.
Something went wrong with that request. Please try again.