本文共 3838 字,大约阅读时间需要 12 分钟。
# cd /opt/modules/openresty/nginx/conf # cp nginx.conf nginx.conf.example # 备份 nginx.conf 文件 default_type application/octet-stream; # 在 http 部分添加,如下两个配置,将加载 Lua 相关库 lua_package_path "/opt/modules/openresty/lualib/?.lua;;"; lua_package_cpath "/opt/modules/openresty/lualib/?.so;;"; index index.html index.htm; error_page 500 502 503 504 /50x.html; # cd /opt/modules/openresty/nginx/conf 在 nginx.conf 的 http 部分添加 :
# cd /opt/modules/openresty/nginx/conf default_type application/octet-stream; # 在 http 部分添加,如下两个配置,将加载 Lua 相关库 lua_package_path "/opt/modules/openresty/lualib/?.lua;;"; lua_package_cpath "/opt/modules/openresty/lualib/?.so;;"; index index.html index.htm; error_page 500 502 503 504 /50x.html; # cd /opt/modules/openresty/nginx nginx: the configuration file /opt/modules/openresty/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/modules/openresty/nginx/conf/nginx.conf test is successful 在 lua.conf 的 server 部分 /lua 请求路径的拦截配置 :
# cd /opt/modules/openresty/nginx/conf default_type 'text/html'; content_by_lua 'ngx.say("hello world")'; # cd /opt/modules/openresty/nginx nginx: the configuration file /opt/modules/openresty/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/modules/openresty/nginx/conf/nginx.conf test is successful 启动 Nginx 或者 重新 Nginx 加载配置
# /opt/modules/openresty/nginx/sbin/nginx # /opt/modules/openresty/nginx/sbin/nginx -s reload # cd /opt/modules/openresty/nginx/conf # /opt/modules/openresty/nginx/conf default_type 'text/html'; # content_by_lua 'ngx.say("hello world")'; 去掉,引入 Lua 脚本文件 content_by_lua_file conf/lua/test.lua; # cd /opt/modules/openresty/nginx nginx: the configuration file /opt/modules/openresty/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/modules/openresty/nginx/conf/nginx.conf test is successful # ./sbin/nginx -s reload # 重新加载配置 # tail -f /opt/modules/openresty/nginx/logs/error.log 2018/05/10 20:04:56 [emerg] 23754#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2018/05/10 20:04:56 [emerg] 23754#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2018/05/10 20:04:56 [emerg] 23754#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2018/05/10 20:04:56 [emerg] 23754#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2018/05/10 20:04:56 [emerg] 23754#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2018/05/10 20:04:56 [emerg] 23754#0: still could not bind() 2018/05/10 20:46:16 [notice] 23890#0: signal process started 2018/05/10 20:48:25 [notice] 23902#0: signal process started 2018/05/10 20:48:29 [error] 23903#0: *1 open() "/opt/modules/openresty/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.242.1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "ci-server", referrer: "http://ci-server/lua" 2018/05/10 20:56:22 [notice] 23925#0: signal process started 转载地址:http://kogab.baihongyu.com/