Nginx As Reverse Proxy IPV6 to IPV4 Website
nginx mod_strip module and textarea
I was asking to Evan Miller if his nginx mod_strip module can honour <textarea> tag. i got quick responses from him.
previous mod_strip module eliminates newline characters within <textarea> list contents. here’s examples with latest mod_strip. I’ve tested it using postfixadmin.
configuration:
server { listen xxx.xxx.xxx.xxx:80; server_name www.example.com; strip on; access_log /var/log/nginx/www.example.com-access.log main; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:80; } }
Nginx Configuration SyntaxHighlighting
Nginx + Vlc Streaming Cheap Webcam
I was experimenting with cheap webcam, vlc on my windows xp workstation. Playing directly using vlc, performance was adequate. but when it came accross network/WAN, delay started increasing between 4-5 seconds(video/audio). i suspect, transcoding are behind these streaming lag. i don’t know what is the best tuning. but here’s the final setting.
start /high vlc.exe --logo-file avatar.png dshow:// :dshow-vdev="VideoCAM Eye" :dshow-adev="SigmaTel Audio" :dshow-caching="0" :sout=#transcode{vcodec=h264{keyint=15,vbv-maxrate=160,vbv-bufsize=160},acodec=mp3,deinterlace,samplerate=44100,sfilter=logo}:std{access=http{mime=video/x-flv},mux=ffmpeg{mux=flv},dst=0.0.0.0:8088/stream.flv,sdp=sap://,name="Webcam 3G"} --ttl 12
Build Nginx RPM With ngx_cache_purge module
I’m not going have much words to say, here we go..
first download nginx source rpm from this excellent contributor/packager and install the source
$ wget http://centos.alt.ru/pub/nginx/0.9/RHEL/SRPMS/nginx-0.9.5-1.el5.src.rpm $ rpm -Uvh nginx-0.9.5-1.el5.src.rpm
Change to /path/rpm/SOURCE and download ngx_cache_purge
$ cd `rpm --eval '%{_sourcedir}'` $ wget http://labs.frickle.com/files/ngx_cache_purge-1.2.tar.gz
Now we need to modified nginx.spec a bit, so it will include ngx_cache_purge module when compiled
$ cd `rpm --eval '%{_specdir}' ` $ vi nginx.spec
Add ngx_cache_source-1.2.tar.gz module to source list as Source20
Source11: nginx_mod_h264_streaming-2.2.7.tar.gz Source20: ngx_cache_purge-1.2.tar.gz
In %prep section add this line %setup -T -D -a 20
%setup -T -D -a 11 %setup -T -D -a 20 %setup -T -D -a 21
In %build section add this line –add-module=%{_builddir}/nginx-%{version}/ngx_cache_purge-1.2 \
... --add-module=%{_builddir}/nginx-%{version}/nginx_upload_module-2.2.0 \ --add-module=%{_builddir}/nginx-%{version}/ngx_cache_purge-1.2 \ --add-module=%{_builddir}/nginx-%{version}/nginx_mod_h264_streaming-2.2.7 ...
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
Cpu0 : 2.9%us, 0.9%sy, 0.0%ni, 88.9%id, 7.2%wa, 0.0%hi, 0.2%si, 0.0%st Cpu1 : 1.8%us, 0.6%sy, 0.0%ni, 95.3%id, 2.2%wa, 0.0%hi, 0.1%si, 0.0%st Cpu2 : 2.4%us, 0.7%sy, 0.0%ni, 94.3%id, 2.5%wa, 0.0%hi, 0.1%si, 0.0%st Cpu3 : 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
# taskset -p 12348 pid 25748's current affinity mask: f # taskset -p 12349 pid 25749's current affinity mask: f # taskset -p 12351 pid 25751's current affinity mask: f # taskset -p 12352 pid 25752's current affinity mask: f # taskset -p 12353 pid 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
$ wget http://centos.alt.ru/pub/php-fpm/5.3.3-2/SRPMS/php-5.3.3-2.el5.src.rpm
Compile and install
$ rpmbuild --rebuild php-5.3.3-2.el5.src.rpm $ sudo rpm -Uvh /path/to/RPMS/php-*
Configuring the default php-fpm for using tcp socket
Edit www.conf
$ sudo vi /etc/php-fpm.d/www.conf
Find line containing
listen = 127.0.0.1:9000
We can make it listening to port what ever we desire, ie 9001 etc
Start php-fpm first instance
$ sudo service php-fpm start
Configuring php-fpm for using unix socket
$ sudo cp /etc/php-fpm.conf /etc/php-fpm2.conf $ sudo cp -rp /etc/php-fpm.d /etc/php-fpm2.d
Edit /etc/php-fpm2.conf
include=/etc/php-fpm2.d/*.conf pid = /var/run/php-fpm/php-fpm2.pid error_log = /var/log/php-fpm/error2.log
Edit /etc/php-fpm2.d/www.conf
listen = /tmp/php-fpm.sock php_admin_value[error_log] = /var/log/php-fpm/www-error2.log