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 ...
随机推荐
- hdoj2476 String painter
题意:有一刷子,能将区间内涂成同一字母.给出src,dst串,问最少涂几次? 用dp[i][j]表示区间[i,j]内最少涂的次数.len=1,2时很明显.len=3时,dp[i][j]要么就在dp[i ...
- thinkphp中页面中时间的默认显示
1,第一我们都知道thinkphp 控制器和页面是通过$this->assgin();或着$this->在页面中要得到的值的随便变量 ,来传值的 比如(此方法是在有时间控件才能使用的) ...
- 将 HttpPostedFile 转换成 Image 或者 Bitmap
代码如下: HttpFileCollection httpfiles = context.Request.Files; files = httpfiles[i]; Image im = Image.F ...
- IOS UI-滚动视图(UIScrollView)
#import "ViewController.h" /* 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤小是极其有限的,因此直接展示在⽤用户眼前的内容也相当有限 ...
- httpclient 连接参数
http.socket.timeout(读取超时) 套接字毫秒级超时时间(SO_TIMEOUT),这就是等待数据,换句话说,在两个连续的数据包之间最大的闲置时间. 如果超时是0表示无限大的超时时间,即 ...
- [转载]python的常用代码模板
URL:http://blog.csdn.net/xingjiarong/article/details/50651235
- mysql 索引原理及查询优化 -转载
转载自 mysql 索引原理及查询优化 https://www.cnblogs.com/panfb/p/8043681.html 潘红伟 mysql 索引原理及查询优化 一 介绍 为何要有索引? ...
- celery(一)分布式任务调度模块简介及运行环境
Celery是Python开发的分布式任务调度模块. Celery本身不含消息服务,它使用第三方消息服务来传递任务. django下有个分支Django-Celery,可以结合django来实现任务的 ...
- L1-014 简单题
这次真的没骗你 —— 这道超级简单的题目没有任何输入. 你只需要在一行中输出事实:This is a simple problem. 就可以了. 输入样例: 无 输出样例: This is a sim ...
- jenkins自动化打包部署
请参考: http://m.blog.csdn.net/article/details?id=50518959 1.启动 jenkins.war ,打开首页 192.168.158.129:8080 ...