Created for Devel.cz Lab s.r.o. (Michal Illich)
Create shorten URL(short.devel.cz/a3) from long URL http://kinohled.cz/praha .
- encode URL to http%3A%2F%2Fkinohled.cz%2Fpraha
- use POST method to create short URL
- example: wget -O- --post-data "url=http%3A%2F%2Fkinohled.cz%2Fpraha" -q "http://short.devel.cz/shorten"
- return short url : http://short.devel.cz/a3
Lua 5.1, nginx with modules:
- https://github.com/agentzh/set-misc-nginx-module/tags
- https://github.com/simpl/ngx_devel_kit/tags
- https://github.com/openresty/lua-nginx-module
- https://github.com/openresty/lua-redis-parser
Copy shorten.conf to /etc/nginx/sites-available/ and create symlink to /etc/ngix/sites/enabled/ .
# Nginx configure
./configure \
--add-module=modules/ngx_devel_kit-* \
--add-module=moduless/set-misc-nginx-module-* \
--add-module=modules/redis2-nginx-module \
--add-module=modules/lua-nginx-module-*
- database 0: id ~> url
- database 1: id ~> hits
- database 2: id ~> [{referer|user_agent}]
- database 3: id ~> hits (when id is not found)
- database 4: id ~> [{referer|user_agent}] (when id is not found)
- database 5: key "count" storing the number of shortened urls; the id is generated by (this number + 1) converted to base 62
mkdir -p /var/www/shorten.localhost/ngdocs/public/
touch "short.devel.cz" >/var/www/shorten.localhost/ngdocs/public/index.html
- replace shorten.localhost by short.devel.cz (your domain)
- replace /shorten by secure /shorten-noh1kaa8oepae (secure URL string)
- replace 127.0.0.1:6379 by redis.localhost:6389 (your redis server)
Target: http://devel.cz/user?destination=home encode by http://meyerweb.com/eric/tools/dencoder/ to http%3A%2F%2Fdevel.cz%2Fuser%3Fdestination%3Dhome
export Target="http%3A%2F%2Fdevel.cz%2Fuser%3Fdestination%3Dhome"
wget -O- --post-data "url=${Target}" -q "http://shorten.localhost/shorten"
wget --max-redirect=0 -O- -q -S $(wget -O- --post-data "url=${Target}" -q "http://shorten.localhost/shorten") 2>&1 | grep Location
echo -e "\n Original: "$A
Based on: https://gist.github.com/MendelGusmao/2356310
Thanks to Lex Vjatkin and Dušan Hokův