nginx: [emerg] unknown directive “if(-f”

Posted by Lloyd on May 19, 2012 at 10:34 am

Nerd Talk

If you’re working on nginx configuration and you can’t start or reload it because you’re getting an error like this:

nginx: [emerg] unknown directive "if(-f" in /etc/nginx/nginx.conf:67
nginx: configuration file /etc/nginx/nginx.conf test failed

You need to make sure that the “if” and the “(” are separated with a space:

# will cause syntax error
if(-f $document_root/$uri.php) {
   rewrite ^(.*) $1.php last;
}
 
# this is correct
# notice the space between "if" and "("
if (-f $document_root/$uri.php) {
   rewrite ^(.*) $1.php last;
}

That should fix the issue and you should be able to start/reload nginx successfully.
As a programmer I tend to assume that “if(-f … )” will work because in essence it’s a valid syntax for if statements. For nginx, you should play by its rules because you’ll get a bunch of these errors if you don’t.

Instagram

Posted by Lloyd on May 13, 2012 at 2:52 pm

I like it, in fact I’m starting to get addicted to it :)
My only complaint so far is it doesn’t actually have a description field as your main caption goes into comments – there’s also no caption/tags edit functionality yet.

New ToDos

Posted by Lloyd on May 13, 2012 at 8:57 am

I figured I should cut down the usual habits to make room for new-old-forgotten ones. Not very long ago I started getting less active on Facebook – it includes no commenting, likes, private messaging, chat, etc. So basically you won’t feel my presence as if you don’t have me as a friend or you’ve totally forgotten my existence. I still visit but not as “sociable” as before, the only activity that I have for the past few months is just uploading landscape photos which nobody appreciates. Now that I’ve said all that, I have a small list which I will try to fulfill as a mini personal goal:

1) Less to no Facebook usage - just because
2) Tweet more – it’s fun!
3) Write new blog posts
4) Visit people’s websites to make new connections – hopefully!
5) Do more photography work
6) Write/read codes on free time (if not doing photography work) to exercise brain
7) Read more tech news and articles to get up to date infos
8) Find a girlfriend (optional)

That sounds about right, I think I will just keep on updating my list as soon as something comes up but it should be a good start.

Blogging again soon!

Posted by Lloyd on May 06, 2012 at 12:37 am

NOT! Well, I might actually do it if I can pull something out of my head but guess what? No one reads this stuff anyway! HAH! I just updated my WordPress installation to the latest and greatest – and they used that silly update message again! I’m also hoping to get those pesky spams out of my previous posts by using the Akismet API.

Next time I’ll try to write something other than site updates ^_^
Morning edit: Want to know a secret? I’m eating a very sweet mango now! Not anymore, that was last night!

Hello 1

Posted by Lloyd on February 26, 2012 at 12:35 pm

Today I have time to update my WordPress installation and I found it funny, too.
“Thank you for updating to the latest version! Using WordPress 3.3.1 will improve your looks, personality, and web publishing experience. Okay, just the last one, but still. :)”

Wait..this turned out to be my first 2012 post!

Happy Birthday!

Posted by Lloyd on November 27, 2011 at 3:42 am

age++;

From coding to capturing moments 2

Posted by Lloyd on November 19, 2011 at 11:41 am

Since the day I started with my career I’ve been so busy, in fact, there’s nothing else to do but work. It’s been the same old routine but because I love what I’m doing, it’s not something to complain about. Not long ago, I wished to do something else, something I haven’t tried and was hoping to fill the empty spaces of my life.. and so my interest in photography started. It was a no brainer choice because it feels close to what I’m doing everyday except I won’t be dealing with codes but pictures. I knew it was not going to be easy because it never was, it needs judgment and skill. I don’t have a good judgment and skill. I’m just some guy entering a new realm with a vast universe of people who have spent their entire lives doing it. But, it’s not a problem. I’m here to learn. This year I was able to travel in different places and do things I haven’t done before – I was able to get away from the city limits. It’s also one of the reasons why I’ve been busy.

I spent majority of my free time tinkering with my camera and traveling with friends who share the same interest. It was a tiring new hobby and is expensive, too. We went to places around the country where people don’t normally go to just to explore and take the time to experiment with our skills. I can count the places we’ve visited but I’ve already lost count how many times I tried to make a good photo and most of them are failures. Despite not being in the level of the experts, I still have the spirit that one day I will be good enough. But for now, I’ll carry my patience with me and learn as we go along.

View some of my photos on flickr and 500px.

Not busy?

Posted by Lloyd on November 19, 2011 at 10:18 am

It’s surprising how I only have few tabs opened during weekends compared on weekdays where I have more than a dozen and more than 2 windows opened. It’s also surprising that I’m taking the time to write about it, too.

Quick update 2

Posted by Lloyd on August 24, 2011 at 5:49 pm

The guy who owns this site is busy and lazy to post. He just logged in today and updated WordPress to the latest version. That’s all.

Adobe Flash player update installation 2

Posted by Lloyd on April 02, 2011 at 9:04 pm

I always notice things, even unimportant ones. Today, I noticed Adobe’s flash update installer. When updating a software you usually see the word Install once and after that you only need to press Next and Done. For Adobe, showing the Install button once is not enough, they show it twice. It’s not a problem really, but I’m guessing or probably the first Install button should indicate a Download button because clicking it doesn’t install the update, it downloads it and then installation happens. I took some screenshots of the update process and it shows that I may be correct with my guess.

First one says install:

The next one which happens after clicking the “Install” button is actually a download:

Next one, there is another “Install” button, this time it’s the real one:

Last one, installation is completed:

See what I’m saying?

Windstruck 1

Posted by Lloyd on March 27, 2011 at 10:06 am

It’s probably the saddest movie I’ve ever watched. It’s so sad I had a teary eye, I really felt it. Srsly. It’s korean and it’s good. There are funny parts at the beginning but through out the movie it’s all sad. Get yourself a good sad movie, I recommend it. After watching, this song should remind you of the movie.

Watch the movie and then watch this another movie as they have some connections.

PHP session not persistent after server migration

Posted by Lloyd on March 27, 2011 at 8:52 am

Nerd Talk

I remember when we setup an Apache web server to move from Lighttpd, after we installed PHP we just copied over the same php.ini file to use the same settings. During testing I had a problem with sessions not persisting between pages, it was a pain to realize the problem at first. The cause of the issue is with the session.save_path, since we just copied over the old php.ini file, the folder path set to where the session should be saved is, well, not existing. I created the folder, the session folder, set write permissions and sessions are flying across pages!
You can find the session.save_path directive in /etc/php.ini and check out where sessions are saved, ex:

session.save_path = "/var/lib/php/session"

I believe it’s not the best practice to set 0777 (means everyone can read/write) permissions for the sessions folder as other users of the server may be able to hijack session files so be careful on this.

Literally, this is the song that played on my head when things started to work. It’s one of my childhood anime song. Watch and listen to this!

I’m eating bacon and rice for breakfast right now, btw. Just saying ;p

Debugging lighttpd’s 404 handler

Posted by Lloyd on March 19, 2011 at 4:38 am

Nerd Talk

I recently fixed an issue in the server that’s related to lighttpd 404 handler. The problem is when a URL is accessed with weird characters lighttpd returns a 404 page. For example, you saw something like this in your page views log and it returned a 404 error:

http://agyuku.net/%C2%A0

The example above results to “http://agyuku.net ” in the browser and returns Page Not Found. Notice the space after .net. The weird character “%C2%A0” is translated by the browser as a space but the server actually sees it as something else. Adding a space after the domain doesn’t really cause the server to react and treat it as a missing page. A solution that should do the work is to add a rewrite rule in lighttpd’s conf file:

"(.+?)(%C2%A0)$" => "$1"

The regular expression matches the weird characters at the end of the URL. When lighttpd receives a page request it will only read the URL without the weird stuff. $1 is a back reference to the regular expression pattern which means use those that matches the first pattern, in this case it’s (.+?). This should actually work but there’s a case due to different server settings, this may not solve the issue as lighttpd doesn’t see “%C2%A0″ as-is when the URL is accessed, it may be something else.

If the above method didn’t work then enabling lighttpd’s debug variables will give a clue to the issue. The debug variables are disabled by default, somewhere in lighttpd.conf set these to be enabled:

debug.log-request-header   = "enable"
debug.log-response-header  = "enable"
debug.log-request-handling = "enable"
debug.log-file-not-found   = "enable"

Once those are set save lighttpd.conf and restart the server. Access the URL with weird characters in the browser to trigger the error and it should write something in the server’s error log. Do a tail to the error log to check the last reported error:

tail -n 150 /path/to/your/error.log

The command above displays the last 150 lines in the error log. Check the displayed errors and there should be something like:

(response.c.221) -- splitting Request-URI
(response.c.222) Request-URI  :  /%C2%A0
(response.c.223) URI-scheme   :  http
(response.c.224) URI-authority:  agyuku.net
(response.c.225) URI-path     :  /%C2%A0
(response.c.226) URI-query    :
(response.c.254) -- sanatising URI
(response.c.255) URI-path     :  /Â
(mod_access.c.135) -- mod_access_uri_handler called
(response.c.391) -- before doc_root
(response.c.392) Doc-Root     : /some/document/root/path
(response.c.393) Rel-Path     : /Â
(response.c.394) Path         :
(response.c.442) -- after doc_root
(response.c.443) Doc-Root     : /some/document/root/path
(response.c.444) Rel-Path     : /Â
(response.c.445) Path         : /some/document/root/path/Â
(response.c.462) -- logical -> physical
(response.c.463) Doc-Root     : /some/document/root/path
(response.c.464) Rel-Path     : /Â
(response.c.465) Path         : /some/document/root/path/Â
(response.c.482) -- handling physical path
(response.c.483) Path         : /some/document/root/path/Â
(response.c.539) -- file not found
(response.c.540) Path         : /some/document/root/path/Â

Notice /%C2%A0 translated as . The browser converts the weird characters as a space but the server treated it differently and converted it to “”. A 404 response is sent by the server because it’s trying to find /some/document/root/path/ which doesn’t exist. We will use the findings above to fix the issue, modify the URL rewrite to something like:

"(.+?)(%C2%A0|Â)$" => "$1"

The pattern now includes the weird character in the URL (just to be sure we handle it as well) and the one that the server see internally (the “”). Save lighttpd and restart the server. Access the URL and it should load up the page without an error.

The above scenario is something I experienced and may be different from issues you may have but I hope it helps someone. And wow, it’s 4 in the morning, I should get some sleep.

More on lighttpd debug variables here.
I used http://agyuku.net an example domain only and it’s not running in lighttpd, it runs in Apache.

Exclude svn folder when copying files to another location

Posted by Lloyd on March 19, 2011 at 3:11 am

Quick Tip

Copy files from an SVN folder to another location and excludes all .svn folders. This copies files from the source to destination recursively, -r.

rsync -r --exclude=.svn /path/to/source /path/to/destination

More about rsync here.

Added to wishlist 2

Posted by Lloyd on February 19, 2011 at 8:27 pm

Apart from wanting to buy a Nintendo 3DS, I also want to buy a DSLR – Nikon D3100. I’m hoping to buy either one of the two this year.

And for today, a random image of Lucy going nuts! xD


^ Back to Top