在Openresty中使用lua语言向请求浏览器返回请求头User-Agent里边的值

可以参考《Linux学习之Ubuntu 20.04在https://openresty.org下载源码安装Openresty 1.19.3.1,使用systemd管理OpenResty服务》安装Openresty。

然后把下边的内容写入到openresty配置文件/usr/local/openresty/nginx/conf/nginx.conf(根据实际情况进行选择文件):

bash 复制代码
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location /lua {
            default_type text/html;
            content_by_lua '
ngx.say("User-Agent: ",ngx.req.get_headers()["User-Agent"])
';
        }
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

然后sudo openresty启动openresty。

最后在浏览器里边输入ip/lua就可以显示出来效果了。

此文章为10月Day 10学习笔记,内容来源于极客时间《Nginx 核心知识 150 讲》

相关推荐
LcGero7 小时前
游戏引擎Luanti的前世今生与技术解析
游戏引擎·lua·游戏开发·我的世界·luanti
scheduleTTe1 天前
Nginx
服务器·前端·nginx
pixcarp1 天前
Nginx实战部署与踩坑总结 附带详细配置教程
服务器·前端·后端·nginx·golang
绿草在线1 天前
SpringBoot请求与响应全解析
spring boot·后端·lua
Slow菜鸟1 天前
Java 开发环境安装指南(7) | Nginx 安装
java·开发语言·nginx
陈皮糖..2 天前
27 届运维实习笔记|第三、四周:从流程熟练到故障排查,企业运维实战深化
运维·笔记·sql·nginx·ci/cd·云计算·jenkins
空中海2 天前
Nginx 知识体系 · 下篇:高级与实战
运维·nginx·spring
心之所向,自强不息2 天前
VSCode + EmmyLua 调试 Unity Lua(最简接入 + 不阻塞运行版)
vscode·unity·lua
身如柳絮随风扬2 天前
Nginx 入门教程:从安装到配置反向代理与负载均衡
运维·nginx·负载均衡
weixin_408099672 天前
Lua请求文字识别ocr api
图像处理·人工智能·后端·ocr·lua·api·文字识别