当前位置: 首页 > news >正文

天津网站优化哪家最专业seo公司是做什么的

天津网站优化哪家最专业,seo公司是做什么的,郴州网站建设,网站模版建站效果: 图片存放路径: /home/jobs/webs/imgs/ ├── default/ │ ├── image1.jpg │ ├── image2.png ├── cats/ │ ├── cat1.jpg │ ├── cat2.gif ├── dogs/ │ ├── dog1.jpg访问http://demo.com/imgs/default 随机返回…

效果:

图片存放路径:

/home/jobs/webs/imgs/
├── default/
│   ├── image1.jpg
│   ├── image2.png
├── cats/
│   ├── cat1.jpg
│   ├── cat2.gif
├── dogs/
│   ├── dog1.jpg

访问http://demo.com/imgs/default 随机返回/home/jobs/webs/imgs/default下的图片
访问http://demo.com/imgs/ 随机返回/home/jobs/webs/imgs/所有的图片(包含所有子目录)

安装openresty

yum方式安装

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
yum install -y openresty

修改默认配置

vi /usr/local/openresty/nginx/conf/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /usr/local/openresty/nginx/logs/nginx.pid;
include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;
}http {log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';sendfile            on;tcp_nopush          on;tcp_nodelay         on;keepalive_timeout   65;types_hash_max_size 2048;gzip on;gzip_buffers 32 4K;gzip_comp_level 9;gzip_min_length 100;gzip_types text/plain application/xml application/json application/javascript text/css text/xml application/x-javascript;gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)gzip_vary on;include             /etc/nginx/mime.types;default_type        application/octet-stream;include /etc/nginx/conf.d/*.conf; # 后面配置会放在/etc/nginx/conf.d/xxx.conf
}# tcp转发
include /etc/nginx/tcp.d/*.conf;

编写lua脚本,实现从指定路径下随机返回图片(包含子路径)
vi /etc/nginx/conf.d/random_image.lua

-- random_image.lua
package.path = package.path .. ";/usr/local/share/lua/5.1/?.lua;/usr/share/lua/5.1/?.lua"
package.cpath = package.cpath .. ";/usr/local/lib/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so"local lfs = require("lfs")
local images = {}-- 从 Nginx 配置中获取 base_dir
local base_dir = ngx.var.base_dir-- 确保 base_dir 以斜杠结尾
if not base_dir:match("/$") thenbase_dir = base_dir .. "/"
end-- 遍历目录及其子目录
local function find_images(dir)for file in lfs.dir(dir) doif file ~= "." and file ~= ".." thenlocal full_path = dir .. filelocal attr = lfs.attributes(full_path)if attr.mode == "directory" then-- 如果是目录,递归查找find_images(full_path .. "/")elseif attr.mode == "file" and (file:match("%.jpg$") or file:match("%.png$") or file:match("%.gif$")) then-- 如果是图片文件(jpg、png、gif),添加到列表table.insert(images, full_path)endendend
end-- 开始查找图片
find_images(base_dir)-- 随机选择一张图片
if #images > 0 thenlocal random_image = images[math.random(#images)]local file = io.open(random_image, "rb")  -- 以二进制模式打开文件if file thenlocal data = file:read("*all")  -- 读取文件内容file:close()-- 根据文件扩展名设置 Content-Typeif random_image:match("%.jpg$") thenngx.header.content_type = "image/jpeg"elseif random_image:match("%.png$") thenngx.header.content_type = "image/png"elseif random_image:match("%.gif$") thenngx.header.content_type = "image/gif"elsengx.header.content_type = "application/octet-stream"  -- 默认类型endngx.say(data)  -- 直接输出图片内容elsengx.say("Failed to open image.")end
elsengx.say("No images found.")
end

在server的配置使用lua脚本
vi /etc/nginx/conf.d/demo.conf

# 处理 /imgs/ 路径的请求
location /imgs/ {# 设置 base_dir 变量set $base_dir "/home/jobs/webs/imgs/";# 提取子路径(例如 /imgs/default -> default)set $sub_path "";if ($uri ~ ^/imgs/(.+)$) {set $sub_path $1;set $base_dir "$base_dir$sub_path/";}# 调用 Lua 脚本content_by_lua_file /etc/nginx/conf.d/random_image.lua;
}

启动openresty

systemctl start openresty

如果出现报错
tail -f /var/log/nginx/error.log

2025/02/11 15:32:47 [error] 15294#15294: *321 lua entry thread aborted: runtime error: /etc/nginx/conf.d/random_image.lua:1: module 'lfs' not found:no field package.preload['lfs']no file '/usr/local/openresty/site/lualib/lfs.ljbc'no file '/usr/local/openresty/site/lualib/lfs/init.ljbc'no file '/usr/local/openresty/lualib/lfs.ljbc'

安装lua开发包

yum -y install lua-devel

确保你已安装 luarocks

yum -y install luarocks

先确认 luafilesystem 是否已经安装。你可以使用 luarocks 命令列出已安装的模块:

luarocks list

如果列表中没有 luafilesystem,那么你需要安装它:

luarocks install luafilesystem

安装完成后,你可以通过以下命令来验证 lfs 模块是否成功安装,如果没有错误输出,说明安装成功:

lua -e "require'lfs'"

然后你可以通过以下命令查找它的路径:

luarocks show luafilesystem

修改 package.path 和 package.cpath
在你的 Lua 脚本的开头添加以下代码,确保包含 lfs 模块的路径:

package.path = package.path .. ";/usr/local/share/lua/5.1/?.lua;/usr/share/lua/5.1/?.lua"
package.cpath = package.cpath .. ";/usr/local/lib/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so"
http://www.15wanjia.com/news/18934.html

相关文章:

  • 老网站权重低的原因营销新闻
  • 域名注册好了如何做网站英文seo实战派
  • 英文网站设计制作焦作网络推广哪家好
  • 网站需要哪些备案十大教育培训机构排名
  • 淘宝客购物网站的怎么做重庆seo网页优化
  • thinkphp旅游网站源码自己的网站
  • ai生成图片在线制作seo的优化技巧和方法
  • 如何创建自己的博客网站电商运营方案计划书
  • 北仑宁波有没有做网站市场营销毕业后找什么工作
  • 网站建设规划书模板网站外链出售
  • 遵义网站建设公司有哪些上海优化公司排行榜
  • 衡州网站建设seo百度经验手机版官网
  • 有什么专业做心理的网站今日头条十大热点
  • 嘉鱼网站建设哪家专业如何开发一个软件平台
  • 大通网站建设百度seo排名优化教程
  • 贵阳学网站建设无代码免费web开发平台
  • 中国建设银行网站类型分析电脑培训网上课程
  • 成都网站建设多少费用网站优化方案怎么写
  • 营销网站的基本要素周口网站seo
  • 中国园林网什么是网站推广优化
  • 跨境电商到什么网站做html家乡网站设计
  • .net空网站做九九乘法表网络营销到底是个啥
  • 龙岗网站制作公司一般多少钱互联网销售平台
  • 微信网站怎么做的好名字吗百度公司怎么样
  • 锦州网站制作公司seo什么意思简单来说
  • 合肥比较好的网站建设公司山西seo推广
  • 合肥网站优化 新浪博客软文写作的基本要求
  • 徐州建设网站希爱力双效片的作用与功效
  • 最新新闻热点事件2022年1月seowhy
  • 怎样快速学好网站建设手机优化软件哪个好用