关于相关的支持程序,也可以从在这里下载并编译安装 openssl http://www.openssl.org/source/ pcre http://www.pcre.org nginx 的 rewrite 网站页面地址重写功能需要正则表达式模块 pcre,另外页面压缩传输需要 zlib 为在配置文件中使用正则表达式,需要安装
关于相关的支持程序,也可以从在这里下载并编译安装
openssl
http://www.openssl.org/source/
pcre
http://www.pcre.org
nginx 的 rewrite 网站页面地址重写功能需要正则表达式模块 pcre,另外页面压缩传输需要 zlib
为在配置文件中使用正则表达式,需要安装pcre和pcre-devel,
注:nginx-0.6.32已经不存在已经安装了pcre及pcre-deve 的rpm包却找不到pcre的问题。
注: 根据 october 2006 message 的消息,md5 在一个现在不再使用的 http 缓存模块中用到,而 sha1 用在一个未完成的 mysql 库模块,所以它们当前都不是必须的
建议仔细阅读wiki上的module说明
http://wiki.codemongers.com/main
./configure --prefix=/usr/local/nginx \
--with-openssl=/usr/include \
--with-http_stub_status_module \
--without-poll_module \
--without-select_module
make
make install
#运行用户
user nobody nobody;
#启动进程
worker_processes 2;
#全局错误日志及pid文件
error_log logs/error.log notice;
pid logs/nginx.pid;
#工作模式及连接数上限
events {
use epoll;
worker_connections 1024;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
#设定mime类型
include mime.types;
default_type application/octet-stream;
#设定日志格式
log_format main '$remote_addr - $remote_user [$time_local] '
'$request $status $bytes_sent '
'$http_referer $http_user_agent '
'$gzip_ratio';
log_format download '$remote_addr - $remote_user [$time_local] '
'$request $status $bytes_sent '
'$http_referer $http_user_agent '
'$http_range $sent_http_content_range';
#设定请求缓冲
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#开启gzip模块
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
#设定access log
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#设定负载均衡的服务器列表
upstream backend {
#weigth参数表示权值,权值越高被分配到的几率越大
#本机上的squid开启3128端口
#server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=6;
server 192.168.8.3:80 weight=6;
}
#设定虚拟主机
server {
listen 80;
server_name 192.168.7.192 www.test.com;
charset gb2312;
#设定本虚拟主机的访问日志
access_log logs/www.test.access.log main;
#如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid
#如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好
#location ~ ^/(img|js|css)/ {
# root /data3/html;
# expires 24h;
#}
#对 / 启用负载均衡
location / {
proxy_pass http://backend;
proxy_redirect off;
#proxy_set_header host $host;
#proxy_set_header x-real-ip $remote_addr;
#proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#设定查看nginx状态的地址
location /nginxstatus {
stub_status on;
access_log on;
#auth_basic nginxstatus;
#auth_basic_user_file conf/htpasswd;
}
}
}
curl -i http://127.0.0.1 查看http头
nginx启动脚本,放于/etc/init.d/nginxd
#!/bin/bash
# nginx startup script for the nginx http server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: - 85 15
# description: nginx is a high-performance web and proxy server.
# it has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
retval=0
prog=nginx
# source function library.
. /etc/rc.d/init.d/functions
# source networking configuration.
. /etc/sysconfig/network
# check that networking is up.
[ ${networking} = no ] && exit 0
[ -x $nginxd ] || exit 0
# start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo nginx already running....
exit 1
fi
echo -n $starting $prog:
daemon $nginxd -c ${nginx_config}
retval=$?
echo
[ $retval = 0 ] && touch /var/lock/subsys/nginx
return $retval
}
# stop nginx daemons functions.
stop() {
echo -n $stopping $prog:
killproc $nginxd
retval=$?
echo
[ $retval = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $reloading $prog:
#kill -hup `cat ${nginx_pid}`
killproc $nginxd -hup
retval=$?
echo
}
# see how we were called.
case $1 in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
retval=$?
;;
*)
echo $usage: $prog {start|stop|restart|reload|status|help}
exit 1
esac
exit $retval