2013年4月2日星期二
Nginx Rule
Install
yum install pcre-devel -y
cd /usr/local/src
wget http://www.myciscolab.net/sources/Agentzh-headers-more-nginx-module-v0.15rc1-3-g6a12aa5.tar.gz
wget http://www.myciscolab.net/sources/Evanmiller-nginx_upstream_hash-2580b21.tar.gz
wget http://www.myciscolab.net/sources/FRiCKLE-ngx_cache_purge-1.3-0-gaf6e0c7.tar.gz
wget http://www.myciscolab.net/sources/Nginx-1.0.2.tar.gz
wget http://www.myciscolab.net/sources/Nginx-upstream-jvm-route-0.1.tar.gz
wget http://www.myciscolab.net/sources/Replay-ngx_http_consistent_hash-77b6940.tar.gz
yum install -y openssl-devel gcc pcre-devel
cd /usr/local/src
tar xzvf Nginx-1.0.2.tar.gz
cd /usr/local/src
tar xzvf Evanmiller-nginx_upstream_hash-2580b21.tar.gz
cd /usr/local/src/nginx-1.0.2
patch -p0 < /usr/local/src/evanmiller-nginx_upstream_hash-2580b21/nginx.patch
cd /usr/local/src
tar xzvf Nginx-upstream-jvm-route-0.1.tar.gz
cd /usr/local/src/nginx-1.0.2
patch -p0 < /usr/local/src/nginx_upstream_jvm_route/jvm_route.patch
cd /usr/local/src
tar xzvf Replay-ngx_http_consistent_hash-77b6940.tar.gz
cd /usr/local/src
tar xzvf Agentzh-headers-more-nginx-module-v0.15rc1-3-g6a12aa5.tar.gz
cd /usr/local/src
tar xzvf FRiCKLE-ngx_cache_purge-1.3-0-gaf6e0c7.tar.gz
vi /usr/local/src/nginx-1.0.2/src/http/ngx_http_upstream.h 删除 125 126
cd /usr/local/src/nginx-1.0.2
./configure --prefix=/usr/local/nginx-1.0.2 --with-debug --with-http_ssl_module --with-http_stub_status_module \
--add-module=/usr/local/src/replay-ngx_http_consistent_hash-77b6940/ \
--add-module=/usr/local/src/evanmiller-nginx_upstream_hash-2580b21/ \
--add-module=/usr/local/src/nginx_upstream_jvm_route/ \
--add-module=/usr/local/src/agentzh-headers-more-nginx-module-6a12aa5/ \
--add-module=/usr/local/src/FRiCKLE-ngx_cache_purge-af6e0c7/
make && make install
ln -s /usr/local/nginx-1.0.2 /usr/local/nginx
Nginx Startup Script
########nginx 启动脚本#########
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
# Taken from http://www.hikaro.com
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
#######################################
3. Purge one js or css file with the command followed.
curl -H "Host: static.test.com" http://1.1.1.1/1.js -I
4. Rewrite
server {
if ( $request_uri ~ '/flash/1.swf') { rewrite ^(.*) http://static.test.com/flash/1.swf permanent;}
}
rewrite ^/A/B$ /1.html last;
5. Nginx Status
Active connections: 291
server accepts handled requests
16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106
server accepts handled requests -- nginx accepted 16630948 connections, handled 16630948 connections (no one was closed just it was accepted), and handles 31070465 requests (1.8 requests per connection)
reading -- nginx reads request header
writing -- nginx reads request body, processes request, or writes response to a client
waiting -- keep-alive connections, actually it is active - (reading + writing)
Ref:
http://www.cyberciti.biz/faq/nginx-see-active-connections-connections-per-seconds/
6. Filter
if ($http_user_agent ~* NSPlayer.*){ return 403; }
订阅:
博文评论 (Atom)
没有评论:
发表评论