FoOlz.us and how to make YOURLS work with Nginx.

at
spacer

Sometimes I wonder… why do I do such things?

Well, honestly I am a megalomaniac, and all the most famous websites have an URL shortening service for their own service. Since (one day) FoOlRulez will be the biggest website evar, I thought… why not adding the short URL service early? Doing it was far harder than thinking of it.

You know, we aren’t using a LAMP (Linux-Apache-MySQL-PHP) server, but an Nginx powered server (LNMP sounds weird tho). This means most of the software needs some fix to work correctly, though it will work much faster. This means YOURLS, the software I intended to use, needed some fix as well.

For this fix, I had to find a solution, and I have found it here: 使用 Yourls 强化你的短网址系统 – Showfom’s Blog.
I have no idea what that URL says… but hey, I found the fix to make YOURLS work!

if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/([0-9a-z]+)/?$ /yourls-go.php?id=$1 last;
}

Gibberish? No this is the code you need to make it work in your Nginx installation! Paste it where you need it. If you don’t know how comment here and I’ll explain a bit further.

Anyway, this made everything work… a bit of styling of the homepage et voilà!

foolz.us

It works! I can’t believe it myself!

Let’s go a bit more indeep with YOURLS. This is a very complete script to make your own URL shortener, by:

  • Lester Chan / @GamerZ on Twitter
  • Ozh RICHARD / @Ozh on Twitter

I think they’re the same who made a few of the plugins I use in this WordPress blog (yeah they are). Anyway, this script is powerful enough to not leave you dry mouthed: you get an API to use the URL shortening service on your server from anywhere, the admin menu lets you control the tidbits you need (ok, most of the controls are via code, but it’s easily done with the explanations), the code has explanation for most of the lines – I in fact edited it to fit my needs better.

Best part of all, it comes with a WordPress plugin, that hooks to the shortening service and makes a short url for every post: even this one post has a shortening url. Then you get automatic submission of the post to Twitter after publishing. The button to submit to twitter on the top is my creation by using the functions (wordpress hooks) that YOURL for WordPress provides.

Tags: foolz.us, Nginx, yourls

This blogpost is part of FoOls/Randomness., Games/Informatics.. You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.

23 Responses to “FoOlz.us and how to make YOURLS work with Nginx.”

  1. spacer woxxy says:

    @gamerz @ozh Thanks for YOURLS =) “FoOlz.us and how to make YOURLS work with Nginx.” foolrulez.org/blog/2009/08/foolz-...

    • spacer ozh says:

      @woxxy Awesome! I’m adding this to the readme. Stay tuned, next version has link stats & more :)

    • spacer gamerz says:

      @woxxy no problem =D

  2. spacer scizzer12 says:

    I love it woxxy.
    Keep up the good work.

    • spacer woxxy says:

      PS:
      foolz.us/a = /a/
      foolz.us/b = /b/

      :3

  3. spacer Nyarth says:

    The URL you linked above says “Use your short-Yourls enhanced web-based system – Showfom’s Blog.” /google translated =P

    So this is basically like Tinyurl/bit.ly huh?

    • spacer woxxy says:

      Lol, thanks for the auto-translation Nyarth.

      And yeah, that’s exactly what it does.

  4. spacer &s=36' class='avatar avatar-36 photo avatar-default' '36' '36' />muge says:

    Oh hey, this is pretty cool.
    Once the database “registers” a custom keyword, does it expire after a while?
    Or is it permanently stored?

    • spacer woxxy says:

      It’s permanent. More precisely, as long as FoOlRulez exists.

      • spacer &s=36' class='avatar avatar-36 photo avatar-default' '36' '36' />muge says:

        Whoa that’s the awesome.

  5. spacer M says:

    What? DickensUrl wasn’t good enough for you?

    FoOls: dickensurl.com/bf68/*an immensely long url*

  6. spacer M says:

    Oh, shoot, I broke the blog. Sorry D:

    • spacer woxxy says:

      lol you keep breaking stuff.

  7. spacer No Comment says:

    This is pretty cool.

  8. spacer Showfom says:

    Haha so you use Nginx, too. I love it~

  9. spacer &s=36' class='avatar avatar-36 photo avatar-default' '36' '36' />Tom says:

    Ok, I don’t know where to put the code above. Please help. Thanks!

  10. spacer Akif says:

    Yeah, I am about to learn how to manage my own database. Good work!

  11. spacer wlsco says:

    woxxy

    Thanks for providing the Nginx rewrite. It works!!!

  12. spacer David Benfell says:

    Help!

    It didn’t work for me.

    The relevant configuration:

    server {
    listen 74.207.227.150:80; ## listen for ipv4
    listen [2001:470:8:1ae::2]:80; ## listen for ipv6
    server_name n4rky.me www.n4rky.me;
    root /home/www/n4rky.me;
    access_log /home/www/n4rky.me/logs/access.log;
    location / {
    index index.php;
    if (!-f $request_filename){
    set $rule_0 1$rule_0;
    }
    if (!-d $request_filename){
    set $rule_0 2$rule_0;
    }
    if ($rule_0 = “21″){
    rewrite ^/([0-9a-z]+)/?$ /yourls-go.php?id=$1 last;
    }
    }
    location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SERVER_NAME $http_host;
    fastcgi_ignore_client_abort on;
    }

    location ~ /\.ht {
    deny all;
    }
    }

    My guess is that it isn’t the rewrite rules you found but the fastcgi implementation. Any ideas?

    Thanks!

  13. spacer Jedidiah Hurt says:

    Based on the contents of the .htaccess file generated by Yourls, this seems to be the most direct translation to Nginx config (seems to be working fine for me, though I didn’t bother to translate the ‘path’ prefix, as I don’t need it):

    if (!-e $request_filename) {
    rewrite ^ /yourls-loader.php last;
    }

  14. spacer David Benfell says:

    Thanks a million! It works!

Leave an Opinion

Click here to cancel reply.

XHTML: You can use these tags: <a class="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>