openresty 短路径服务器

2017-03-13  本文已影响0人  绝世懒人

需求: 微信扫码,如果url过长将会耗时更长,为了减少扫码耗时我们要将url地址缩短。
所以我用openresty通过两个步骤实现了此方法。
本文涉及:
1.get和post请求兼容处理。
2.url在md5加密之后,如何进一步加密缩短,并尽量保证数据唯一性
3.因为写出来之后,代码行数比较多。所以我进行了拆分,将代码拆成了几个lua脚本进行调用执行。美观简化了lua代码
PS: 核心内容在附件,里面附有核心实现代码

Paste_Image.png

服务器系统:CentOs 7.0
脚本: dcang.zip , nginx.conf
脚本下载地址 :
http://ojca5b9d2.bkt.clouddn.com/dcang.zip

安装环境:
yum install readline-devel pcre-devel openssl-devel gcc

一、解压并安装:
tar -xzvf openresty-VERSION.tar.gz

./configure
(/opt/openresty 是安装目录)
./configure --prefix=/etc/openresty
--with-luajit
--without-http_redis2_module
--with-http_iconv_module
--with-http_postgres_module
(可能会出错:
./configure: error: ngx_postgres addon was unable to detect version of the libpq library.
ERROR: failed to run command: sh ./configure --prefix=/etc/openresty/nginx ...

解决方法,执行:
yum install postgresql-devel

编译:
make && make install

二、环境搭建
创建两个目录,一个放配置文件,一个放日志
mkdir /etc/work
cd /etc/work
mkdir logs/ conf/

(可选)
为了方便使用nginx,配置环境变量:
Vim /etc/profile

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH

之后退出,source /etc/profile 或者 重启生效

放置脚本:
cd /etc/openresty/openresty/lualib
unzip dcang.zip
并将nginx.conf文件放入/etc/work/conf

三、启动
在work目录下,启动
nginx -p pwd/ -c conf/nginx.conf

查看是否成功:
curl http://localhost:6699/

上一篇 下一篇

猜你喜欢

热点阅读