Resolving “‘unknown’: unknown terminal type.” error

Last day, after updating the repositories and installing the updated packages on my Debian Lenny, I found that I could no longer run top or use nan or vi to open a file. It threw up this nasty error:

#top
'unknown': unknown terminal type.

After a bit of sleuthing, I came to the conclusion that my default console terminal type was defined as ‘unknown’, which, obviously, isn’t correct. To display your default terminal type, use this :

echo $TERM

If it says something other than linux, there is your problem.

To change it to linux, just type in:

export TERM=linux

To make the change permanent:

echo 'export TERM=linux' >> ~/.bash_profile

WordPress permalinks in nginx

nginx logoWordPress generally works out-of-the box on nginx. The posts load fine, the functions in the dashboard work pretty well, until you come to the permalinks. If you are on Apache, with mod_rewrite, WordPress will automatically add the required rewrite rules to your .htaccess file for permalinks to work. But for nginx, you have to add the rules manually.

Moreover, when WordPress detects that mod_rewrite is not loaded (which is the case with nginx), it falls back to using PATHINFO permalinks, which inserts an extra ‘index.php’ in front. This hasn’t been much of a problem for me as I have been using the custom structure option to remove the index.php. It has been working fine for me. (Screenshot below)

Apart from that, you will also need to edit your nginx configuration file to make the permalinks work. We will use the try_files directive (available from nginx 0.7.27+) to pass URLs to WordPress’s index.php for them to be internally handled. This will also work for 404 requests.

  • If your blog is at the root of the domain (something like http://www.myblog.com), find the “location /” block inside the configuration file, and add the following line to it.
    try_files $uri $uri/ /index.php?q=$uri&$args;

    It should look like this after the edits :

            location / {
                    index  index.php index.html index.htm;
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
  • If your blog is in a subfolder (say /blog), you’ll have to add an extra “location /blog/” block to your configuration file :
            location /blog/ {
                    try_files $uri $uri/ /blog/index.php?q=$uri&$args;
            }

After you have finished making the changes in the configuration file, reload the nginx configuration by :

nginx -s reload

WordPress’ pretty permalinks should work fine now.

IPv6 support in nginx

nginx logoTo enable IPv6 support in nginx, we need to check whether it has been compiled with --with-ipv6 flag. To check, fire up the terminal and type in this command :

nginx -V

The results should be something like this :

nginx version: nginx/0.7.65
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --with-http_realip_module --with-mail --with-mail_ssl_module --with-ipv6 --add-module=/build/buildd/nginx-0.7.65/modules/nginx-upstream-fair

Pre-compiled Debian/Ubuntu packages already has IPv6 support built-in.

Now we need to edit the configuration file to tell nginx to bind to IPv6 addresses(as well as IPv4 addresses).

sudo nano /etc/nginx/sites-available/default

Depending on your configuration, this file might be located somewhere else. (Check /usr/local/nginx/conf/nginx.conf if you compiled nginx manually)

Search for listen directives and change them as follows:

listen [::]:80;

This will make nginx bind to both IPv6 and IPv4 addresses.

In order to bind to IPv6 addresses only (no IPv4), use the following:

listen [::]:80 default ipv6only=on;

In order to bind to a specific IPv6 address:

listen [2001:6f8:1c00:16d::2]:80;

When you are done, reload the nginx configuration file by typing in :

nginx -s reload

Now we have to check whether nginx is listening to both IPv6 and IPv4 requests:

netstat -tulpna | grep nginx

You’ll get something like this :

tcp6       0      0 :::80                   :::*                    LISTEN      1891/nginx

You have successfully configured nginx to respond to IPv6 requests.

Nginx reduces page load time, increases Googlebot activity

nginx logoAfter a small incident with a shared host, I moved my phpBB forum and a few other static sites to a VPS running on nginx. Nginx is a small, lightweight but very efficient web server created by Igor Sysoev, originally developed for www.rambler.ru, Russia’s second-largest web site. Due to it’s light-weightedness and efficiency, it is used by a lot of high traffic sites like WordPress, Hulu, Github, Ohloh, SourceForge, TorrentReactor, etc. After moving to Nginx, I noticed a significant improvement in page load times. The pages on the site load in around 0.0X seconds now, as reported by the phpBB’s measurement system. The pages also seem to be snappier as compared to the time when I was on Litespeed.

I recently noticed that apart for the decrease in page loading time, the activity of Googlebot has increased manyfold. Here’s a screen-shot of the report from Google Webmaster Tools :

Google Webmaster Tools NginxNot bad, eh?

More recently, I moved this blog to the VPS running on Nginx, and I have not been disappointed. This blog is running on WordPress 3.0.1, with no caching plugins. The posts seem to load faster than ever, as evident from this Google Webmaster Tools report :

google webmaster tools nginx techtitbits

I couldn’t be more happy.

PS: Of course, some of the speed improvement can be attributed to the fact that I moved from a shared server to a VPS, but that doesn’t undermine the awesomeness that is Nginx.

Enable directory listing in nginx

nginx logoEnabling directory listing in a folder in nginx seems simple enough with just an autoindex on; directive inside the location directive. However, for some reason, it didn’t work for me.

I finally got it to work by moving the root directive out of location.
So, if you have something like this :

server {
        listen   80;
        server_name  domain.com www.domain.com;
        access_log  /var/...........................;
        location / {
                root   /path/to/root;
                index  index.php index.html index.htm;
        }
        location /somedir {
               autoindex on;
        }
}

Change it to :

server {
        listen   80;
        server_name  domain.com www.domain.com;
        access_log  /var/...........................;
        root   /path/to/root;
        location / {
                index  index.php index.html index.htm;
        }
        location /somedir {
               autoindex on;
        }
}

Directory indices should show flawlessly now.
(A live example can be found here.)