/ linux

Using Nginx As A Simple URL Shortener

For a long time I used bit.ly (and tinyurl before that) to provide friends and students with short URLs. But that was not perfect. Using bit.ly meant I lost branding control, and that the URLs I wanted were not always available.

Owning a domain and a VPS makes it trivial to build your own url shortener. Here's how.

Shortening URLs with nginx

A URL shortener is just an HTTP server that responds with 301 when known shortcuts are accessed. The following nginx configuration does the trick:

server {
        server_name s.ynonperek.com;

        location /ddg {
                return 301 https://www.duckduckgo.com;

And now you can visit http://s.ynonperek.com/ddg to reach duckduckgo.