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

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

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à!

http://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:

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.

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

  1. 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?

  2. 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?

  3. 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 http://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!

  4. 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;
    }

  5. Pedro Galvan says:

    Hi guys. Used the info here to set up yourls in nginx. Pretty much everything is working except stats. So, from the admin interface, if I click on the icon for stats of a specific link, it tries to go to that url appending a ‘+’ at the end. But my nginx doesn’t recognize that url and sends a 403.

    Has anybody else had this problem?

  6. Ashley says:

    So, would this mean that members could rqseuet their own URL of, for example, bpsite.com/username and bpsite.com/groupname? Or are the group short URLs automatically generated?They are automatically generated. If you have the pretty setting turned on, then they’re generated as username’ or groupname’. Otherwise they are random.If so, where do group admins/members find the group’s short URL?It’s printed into the group/profile header.It’s be cool if this could be integrated into Achievements, when, for example, a member uploads 100 photos, they’d unlock their own short username URL.Good idea. I’ll put a filter in the next version that would allow this to be built.Are group admins and members able to view their own short URL stats – such as bpsite.com/username+ ?No, but it’s an interesting idea. The shortcoming of this would be that YOURLS only keeps track of visits to the short URL, so it wouldn’t be an accurate count of *all* visits.

  7. Rohit says:

    , I think it’s perfectly leigaimtte and healthy to want to know which of the stuff you share is appealing and which is not, and stats can be a way to do that.In any case, the API is the real reason for having something more robust like YOURLS. It’s set up so that you can have protected access, which allows (for example) for me to do what I’ve suggested here in the post, which is to give accounts to a few friends without opening it up to the whole world.

  8. Aqram says:

    It has always been a coercnn of mine, when using a free service for shortening ones URLs, of them going out of business. I have not come across the term “linkrot” before and was surprised to find that this is the word that they actually use describe this problem.I have heard good things about the software YOURLS, developed by Ozh Richard.

  9. Christoper says:

    - What the plugin awlols is for you to attach traffic returning to your blog from Twitter to a specific campaign in Google Analytics. It assumes you’ve already got Google Analytics installed on your blog via some other means; either a Google Analytics plugin or having added it to your blog theme.@David – I assume that Marsedit is using the XMLRPC publishing protocol. Have you enabled remote publishing in the plugin settings?

  10. Francesca says:

    I agree with Christopher! By accident I tteewed a comments made from my new WP Wall plug-in. That may even be a bug In any case, everyone MUST go and fix their settings for this as soon as they install it, rather than wait for a boo boo to happen, like I did.As far as install, etc. A BREEZE!!! Thank you

  11. Diana says:

    Looks great I especially like the meta_type, meta_value and tags fildes. I’m really looking forward to being able to store more than just the short and long URLs get crackin!Kurt

  12. Gak says:

    Rod,YOURLS does offer the ability to edit links once you’ve ceretad them to update the link or the short code related to it.After testing a few, it doesn’t allow you to use UNC paths in the URL to shorten. That might just be a check that the program does to verify that it’s a good URL though, so another program might offer it.I’ve accomplished what you’re trying to do before by just using the HOSTS file. I edited the HOSTS file to translate a name I typed into the IP address of the server. It seemed to work out pretty well but that was only on one machine and probably a simpler use than how you’re trying to use it. I’d be interested to know if anybody else has other suggestions.

  13. Dina says:

    Hi Ludo,the plugin is ablvaaile for FF6 since August 21, 2011. You’ll find it .Unfortunately it has to get reviewed by the dev-team of Mozilla before you’ll find it on it’s main page (or in the search results). I submitted the plugin for review on August 21, but it’s still waiting for a review in the queue. (Currently it’s on position 56 of 241, after ~1 month!!). As long as it’s in this queue I cannot do anymore than waiting (and hoping that Mozilla extends it’s dev-team to fit it’s extremely shortened release cycles).I hope this answer helps,Martin

Leave an Opinion

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