user coolnet coolnet;
worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log logs/debug.log debug;
pid /var/run/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;
events {
use epoll;
worker_connections 65535;
}
include rtmp.conf;
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;
#防DDOS攻击,勿删除
#lua_code_cache off;
lua_package_path "/usr/local/openresty/lualib/resty/?.lua;;";
access_by_lua_file "lua/test.lua";
limit_conn_zone $binary_remote_addr zone=ddos:10m;
limit_req_zone $binary_remote_addr zone=oneddos:10m rate=2r/s;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
keepalive_timeout 0;
#keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-_javascript_ text/css application/xml;
gzip_vary on;
server
{
listen 80;
#server_name localhost;
#include rewrite.conf;
index index.php index.html index.htm default.html default.htm default.php;
root html;
access_log logs/192.168.1.88.log;
error_log logs/192.168.1.88.err;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location /M00/ {
alias /data/fastdfs/store/data/;
ngx_fastdfs_module;
}
access_log off;
}
include vhost/*.conf;
}
请各位帮帮忙,不甚感激
在 2013年12月12日星期四UTC+8上午11时45分08秒,agentzh写道:
Hello!
2013/12/11 <xhn5...@gmail.com>:
> 我想在http块用lua定义一段全局逻辑代码,发现access_by_lua_file 'lua/test.lua';
> 怎么都无效。里面只一句ngx.say('test')都没有执行
> access_by_lua '
> ngx.print("test")
> ';
> 因为我curl 时没有输出啊,但是网上说是可以的啊,请问是版本的原因吗?我nginx1.4.3
>
access_by_lua 可以在 http {} 块里工作,效果是 http {} 里面定义的所有 location 都会继承此设置。
我这里有一个可以工作的最小化的完整示例:
https://gist.github.com/agentzh/7922870
测试结果如下:
$ curl localhost:8080/t
hello from access_by_lua
$ curl localhost:8080/
hello from access_by_lua
$ curl localhost:8080/blahblahblah
hello from access_by_lua
显然结果都如期望。
你可以在你本地尝试我的这个示例。
Regards,
-agentzh