Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Oct 262011

The difference between last and break used in Nginx URL rewrite


When you rewrite URL using the Nginx's rewrite directive, you might be confused that what are the exact difference between last and break?

From the official site:

last - completes processing of rewrite directives, after which searches for corresponding URI and location
break - completes processing of rewrite directives and breakes location lookup cycle by not doing any location lookup and internal jump at all

So: both directives will end the rewrite cycle, but break will not do any location lookup and internal jump afterward.

Oct 232011

Debug Nginx configuration using the echo module


When you want to confirm you have configured Nginx correctly, e.g. make sure you have the right rewrite rules. The easiest way is to use the echo module to debug.


location / {
    rewrite ^/foo /bar break;
    echo $uri; # try with other variables you want to trace

When you use curl to request the page, you should receive something like:

# curl
Oct 202011

Enable debug log for Nginx


Sometimes, you need to enable the debug log feature on Nginx for troubleshooting some nasty issues.

Firstly, you need to make sure you have configured nginx to build with the debugging feature enabled

# ./configure --with-debug ...

If you are using the installing using apt-get on Ubuntu, you are ready to go by setting the following in the Nginx config:

error_log  /path/to/log  debug;

Don't forget to restart the Nginx to take effect.

Jul 272011

Calculating the max client in Nginx


If you use Nginx as a web server, the max. number of client can be served at the same time by Nginx should be calculated by the following formula:

max_clients = worker_processes * worker_connections

But this does not equal to the number of users can be served at the same time by Nginx, since a lot of browsers open 2 connections to the web server at the same time.