Nginx worker_cpu_affinity

By Default, without setting worker_cpu_affinity directive in nginx.conf, linux kernel will spread all nginx’s worker all over CPUs.

I have 4 logical CPUs on my server, which is CPU0 – CPU3

1Cpu0  :  2.9%us,  0.9%sy,  0.0%ni, 88.9%id,  7.2%wa,  0.0%hi,  0.2%si,  0.0%st
2Cpu1  :  1.8%us,  0.6%sy,  0.0%ni, 95.3%id,  2.2%wa,  0.0%hi,  0.1%si,  0.0%st
3Cpu2  :  2.4%us,  0.7%sy,  0.0%ni, 94.3%id,  2.5%wa,  0.0%hi,  0.1%si,  0.0%st
4Cpu3  :  1.9%us,  0.7%sy,  0.0%ni, 96.7%id,  0.6%wa,  0.0%hi,  0.0%si,  0.0%st

Using default setting, nginx’s worker always bind to those 4 logical CPUs. which is has “f” bitmask

1# taskset -p 12348
2pid 25748's current affinity mask: f
3# taskset -p 12349
4pid 25749's current affinity mask: f
5# taskset -p 12351
6pid 25751's current affinity mask: f
7# taskset -p 12352
8pid 25752's current affinity mask: f
9# taskset -p 12353
10pid 25753's current affinity mask: f

CPU affinity is represented as a bitmask (given in hexadecimal), with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU.
Examples:

How To Make php-fpm Listen On Both Tcp And Unix Socket?

I need to make php-fpm listeing on both tcp/unix socket, and this is how it done.
(this was not pretty workarround i guess, but it work 😀 )
first  download php rpm source

Compile and install

1$ rpmbuild --rebuild php-5.3.3-2.el5.src.rpm
2$ sudo rpm -Uvh /path/to/RPMS/php-*

Configuring the default php-fpm for using tcp socket
Edit www.conf

1$ sudo vi /etc/php-fpm.d/www.conf

Find line containing

1listen = 127.0.0.1:9000

We can make it listening to port what ever we desire, ie 9001 etc
Start php-fpm first instance

1$ sudo service php-fpm start

Configuring php-fpm for using unix socket

1$ sudo cp /etc/php-fpm.conf /etc/php-fpm2.conf
2$ sudo cp -rp /etc/php-fpm.d /etc/php-fpm2.d

Edit /etc/php-fpm2.conf

1include=/etc/php-fpm2.d/*.conf
2pid = /var/run/php-fpm/php-fpm2.pid
3error_log = /var/log/php-fpm/error2.log

Edit /etc/php-fpm2.d/www.conf

1listen = /tmp/php-fpm.sock
2php_admin_value[error_log] = /var/log/php-fpm/www-error2.log

Nginx, Subdirs Without Trailing Slash

If you set [xml] location /mail/ { fastcgi_pass localhost:8888; ... } [/xml] and request "/mail" then nginx will return external redirect to "/mail/". If you do not want the redirect, then [xml] location = /mail { fastcgi_pass localhost:8888; fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_param SCRIPT_NAME /index.php; root /var/www; } location /mail/ {…

Nginx, Geo IP and Distributed Server

When you have many networks, which are located far apart and in different location. You want users to access the server closest to their network. town1 users when accessing the main server, the server will diredirect town1.example.com, and the town2's users will be redirected to town2.example.com. [xml] http { geo…

Nginx, limit website visitor bandwidth by country

First grab this perl script which you will use to convert Maxmind’s geo IP database into a format usable by Nginx. make it executable [bash] $ chmod 755 geo2nginx.pl [/bash] Then download Maxmind’s latest GeoLite country database in CSV format. Unzip it, and run perl script [bash] $ unzip GeoIPCountryCSV.zip…

Linux related Picture Found On Internet

Linux (commonly /ˈlɪnəks/ lin-əks in English, also pronounced /ˈlɪnʊks/ lin-uuks in Europe) refers to the family of Unix-like computer operating systems using the Linux kernel. Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers, routers, and video game consoles, to mainframes and…

Nginx enabling TLS SNI support on centos 5

By default centos 5.x has openssl-0.9.8e which is not have tls extention for  sni support. this is workaround on how to get nginx 0.8.48 rpm with TLS SNI enabled

Step 1:

download openssl source, example  openssl-0.9.8l. extract it in /usr/src

1$ cd /usr/src
2$ wget http://www.openssl.org/source/openssl-0.9.8l.tar.gz
3$ tar xvzf openssl-0.9.8l.tar.gz

Step 2:

Download nginx rpm source, example nginx-0.8.49-1.el5.src.rpm

Move to directory where the spec file is in and edit nginx.spec

1$ cd /path/to/rpm/SPECS/
2$ vi nginx.spec