可以參考《Linux學(xué)習(xí)之Ubuntu 20.04在https://openresty.org下載源碼安裝Openresty 1.19.3.1,使用systemd管理OpenResty服務(wù)》安裝Openresty。
然后把下邊的內(nèi)容寫入到openresty配置文件/usr/local/openresty/nginx/conf/nginx.conf
(根據(jù)實(shí)際情況進(jìn)行選擇文件):
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
啟動(dòng)openresty。
最后在瀏覽器里邊輸入ip/lua
就可以顯示出來效果了。文章來源:http://www.zghlxwxcb.cn/news/detail-725086.html
此文章為10月Day 10學(xué)習(xí)筆記,內(nèi)容來源于極客時(shí)間《Nginx 核心知識(shí) 150 講》文章來源地址http://www.zghlxwxcb.cn/news/detail-725086.html
到了這里,關(guān)于在Openresty中使用lua語言向請(qǐng)求瀏覽器返回請(qǐng)求頭User-Agent里邊的值的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!