openresty 使用cuid 类库生成短链接id
cuid 是一个不错的id 生成算发,类似的有shortid 、hashid
演示使用lua 包集成openresty 做测试
使用docker-compose 运行
dockerfile
FROM openresty/openresty:alpine-fat
RUN apk add --no-cache curl perl
RUN /usr/local/openresty/luajit/bin/luarocks install cuid
EXPOSE 80
COPY nginx.conf usr/local/openresty/nginx/conf/
docker-compose file
version: "3"
services:
id:
build: .
image: dalongrong/cuid-openresty
ports:
- "8080:80"
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.html index.htm;
}
location /id {
default_type text/html;
content_by_lua_block {
local cuid = require("cuid")
local id = cuid.generate ( )
local slug = cuid.slug ( )
ngx.say("<div> shortid "..slug.."</div>".."<div>long id"..id.."</div>")
}
}
location /alert {
default_type text/html;
content_by_lua_block{
ngx.say([[<script>alert("error")</script>]])
}
}
location /ip {
default_type text/html;
content_by_lua_block{
ngx.say(ngx.var.remote_addr)
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
构建&&运行
- 构建
docker-compose build
- 运行
docker-compose up -d
- 访问
open http://localhost:8080/id
- 效果

参考资料
https://hub.docker.com/r/openresty/openresty/
https://github.com/rongfengliang/openresty-cuid-demo
https://github.com/marcoonroad/cuid
https://www.npmjs.com/package/cuid
openresty 使用cuid 类库生成短链接id的更多相关文章
- 使用plv8+hashids生成短链接服务
有写过一个集成npm plv8 以及shortid生成短链接id服务,实际上我们可以集成触发器自动生成url对应的短链接地址,hashids也是一个不错的选择. 以下是一个别人写的一个博客实现可以参考 ...
- openresty && hashids&& redis 生成短链接
1. 原理 a. 从redis 获取需要表示的短链接的id( redis incr) b. hashids 编码 id c. openresty conteent_by_lu ...
- Java生成短链接
为什么要生成短链接 微博之所以要是使用短链接,主要是因为微博只允许发140 字,如果链接地址太长的话,那么发送的字数将大大减少. 那么使用短链接的作用有哪些呢?1.字数,2.统计,3.监控,4.过滤 ...
- java,url长链接生成短链接,短链接生成器,自定义字符串,对字符串md5混合KEY加密,根据短链接获得key值,不重复的随机数,不重复的随机字符串
java,url长链接生成短链接,短链接生成器,自定义字符串,对字符串md5混合KEY加密,根据短链接获得key值,不重复的随机数,不重复的随机字符串 package com.zdz.test; im ...
- 新浪微博API生成短链接
通过新浪微博API,生成短链接,支持一次性转多个长链接 什么是短链接 短链接,通俗来说,就是将长的URL网址,通过程序计算等方式,转换为简短的网址字符串. 短链接服务 国内各大微博都推出了自己的短链接 ...
- PHP生成短链接方法
PHP生成短链接方法方法一:新浪提供了长链接转为短链接的API,可以把长链接转为 t.cn/xxx 这种格式的短链接. API: http://api.t.sina.com.cn/short_url/ ...
- 用PHP和Python生成短链接服务的字符串ID
假设你想做一个像微博短链接那样的短链接服务,短链接服务生成的URL都非常短例如: http://t.cn/E70Piib, 我们应该都能想到链接中的E70Piib对应的就是存储长链接地址的数据记录的I ...
- 生成短链接的URL
假设你想做一个像微博短链接那样的短链接服务,短链接服务生成的URL都非常短例如: http://t.cn/E70Piib, 我们应该都能想到链接中的E70Piib对应的就是存储长链接地址的数据记录的I ...
- plv8 + hashids 生成短连接id
此文章是转载文章的一个学习,稍有改动 环境准备 plv8 环境 version: '3.6' services: postgres: image: dalongrong/plv8:2.3.12 ...
随机推荐
- input不记录之前输入的值
autocomplete="off" // input中添加这个属性
- 绝对干货!!css3字体图标—丰富的阿里图标库iconfont的使用详解
在移动端Web项目开发中,我们往往需要用到一些小图标,比如搜索,返回,小菜单,小箭头等等..这如果还用切图你就OUT了.. 而这时CSS3提供的字体图标无疑是我们最好的选择,它就像字体一样,可以设置大 ...
- python-day71--django多表操作
表关系: 1 一对多 2 多对多 3 一对一 添加记录: 一对多:书与出版社 #创建一对多: publish=models.ForeignKey("Publish") 注意:pub ...
- 附录A——面向对象基础
在学习设计模式之前,C#语言中一些基本的面向对象的知识还是应该具备的,比如像继承.多态,接口.抽象类,集合.泛型等. A.2 类与实例 什么是对象? 一切事物(事和物)都是对象,对象就是可以看到.感觉 ...
- 等待进程结束wait,waitpid
当子进程先于父进程退出时,如果父进程没有调用wait和waitpid函数,子进程就会进入僵死状态. pid_t wait(int *status); pid_t waitpid(pid_t pid, ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- 最全的CSS浏览器兼容问题【FF与IE】
1. Div居中问题 div设置 margin-left, margin-right 为 auto 时已经居中,IE 不行,IE需要设定body居中,首先在父级元素定义text-algin: cent ...
- [转载]oracle位图索引
原文URL: http://lzfhope.blog.163.com/blog/static/63639922013119112011947/ 很详细,推荐看5遍
- L1-052 2018我们要赢
2018年天梯赛的注册邀请码是“2018wmyy”,意思就是“2018我们要赢”.本题就请你用汉语拼音输出这句话. 输入格式: 本题没有输入. 输出格式: 在第一行中输出:“2018”:第二行中输出: ...
- DevExpress v17.2新版亮点—DevExtreme篇(三)
用户界面套包DevExpress DevExtreme v17.2终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExtreme v17.2 的New Color Sche ...