参考资料
https://github.com/chaoslawful/lua-nginx-module
https://github.com/agentzh/echo-nginx-module
将nginx,lua-nginx-module,echo-nginx-module从git上下载下来。
我的都下载到了
/home/fansxnet/gitproject/目录下了。
cd /home/fansxnet/gitproject/nginx
./configure --user=fansxnet --group=fansxnet --prefix=/home/fansxnet/gitproject/nginx --add-module=/home/fansxnet/gitproject/echo-nginx-module --add-module=/home/fansxnet/gitproject/lua-nginx-module
adding module in /home/fansxnet/gitproject/echo-nginx-module
+ ngx_http_echo_module was configured
adding module in /home/fansxnet/gitproject/lua-nginx-module
checking for Lua library ... found
checking for export symbols by default ... found
+ ngx_http_lua_module was configured
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for system md library ... not found
checking for system md5 library ... not found
checking for OpenSSL md5 crypto library ... found
checking for sha1 in system md library ... not found
checking for OpenSSL sha1 crypto library ... found
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
nginx path prefix: "/home/fansxnet/gitproject/nginx"
nginx binary file: "/home/fansxnet/gitproject/nginx/sbin/nginx"
nginx configuration prefix: "/home/fansxnet/gitproject/nginx/conf"
nginx configuration file: "/home/fansxnet/gitproject/nginx/conf/nginx.conf"
nginx pid file: "/home/fansxnet/gitproject/nginx/logs/nginx.pid"
nginx error log file: "/home/fansxnet/gitproject/nginx/logs/error.log"
nginx http access log file: "/home/fansxnet/gitproject/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
编译的时候,提示库没有找到的,可以根据提示的库名,google后,一个个安装
make
# 如果没有错误,这一步就编译成功了。
cd objs/
ls
addon autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
#看到nginx,编译成功了。
修改配置文件 /home/fansxnet/gitproject/nginx/conf/nginx.conf
# 用户名,组
user fansxnet fansxnet;
worker_processes 1;
#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 logs/host.access.log main;
#设置虚拟目录
root /home/fansxnet/gitproject/nginx/html/;
location / {
root html;
index index.html index.htm;
}
#测试用的地址,多个文件合并成一个返回给浏览器
#http://127.0.0.1/merge?/js/jquery-1.2.6.min.js&/js/index.js
location /merge {
default_type 'text/javascript';
echo_foreach_split '&' $query_string;
echo "/* JS File $echo_it */";
echo_location_async $echo_it;
echo;
echo_end;
}
#测试用的地址,测试lua脚本执行 http://127.0.0.1/recur?num=5
location /recur {
# MIME type determined by default_type:
default_type 'text/plain';
content_by_lua '
local num = tonumber(ngx.var.arg_num) or 0
if num > 50 then
ngx.say("num too big")
return
end
ngx.say("num is: ", num)
if num > 0 then
res = ngx.location.capture("/recur?num=" .. tostring(num - 1))
ngx.print("status=", res.status, " ")
ngx.print("body=", res.body)
else
ngx.say("end")
end
';
}
# 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 HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
切换到root下。
注意我的当前路径是能够nginx源码目录 /home/fansxnet/gitproject/nginx/objs
./nginx
#启动后可以测试了
./nginx -s stop
# 停止了