Solution for URL shortening: nginx, postgres, json.
Includes: website, android application, and simple bash script for url shortening.
Live example: hda.me
- nginx - nginx itself, better use source package from nginx.org repository for your favourite GNU/Linux distribution as base.
- postgres - better use repository from postgresql.org.
- nginx devel kit - lua-nginx-module dependency
- nginx lua module
- nginx postgres module
- nginx json module
- conf folder includes nginx.conf section example, site-enabled/sitename (vhost) example, sql file to import and debian rules file example useful for package rebuild.
- script folder includes shortening bash script example.
- website folder includes main url shortener website page example
- android_app folder includes example android application, where apk file is actual application used for hda.me url shortener website.
Once you have nginx and the needed modules installed you can start nginx up with the the configuration in this found in /conf and /website folders.
You also need to setup a database in your PostgreSQL-server and create separate table, don't forget set password. Use the /config/database.sql file to do it for you. After you are done adjust the settings to your environment in the nginx configuration.
Example:
Creating user and database:
CREATE USER "user" WITH PASSWORD 'password';
CREATE DATABASE databasename WITH OWNER "user";
Importing:
psql -h localhost -d databasename -U user -f database.sql
##Usage
- Script
Edit host, chmod 755, and copy to /usr/local/bin/ Usage: urlhda http[s]://your_long_url_here - Website
Install, configure, edit index.html to change appearance for your needs and your done. - Android app
Change host in index.html, import to android studio, sign apk with your personal key and finally build apk.
You can shorten URLs with a POST-request:
curl -X POST https://website.name/add?url=http://add.me
This will give you JSON-response back with the generated 5 character UID:
[{"uid":"abcd5"}]
With that you can go to for example to https://website.name/abcd5 and you will be redirected to http://add.me
##Other
Original idea: Sebastian Gräßl, forked from https://github.com/bastilian/sebas
Bitcoin donate: 1N5czHaoSLukFSTq2ZJujaWGjkmBxv2dT9