Ngnix use proxy 配合lighttpd处理静态文本

反向代理服务已经越来越广泛的应用于高负载的Web站点中,常用来作为Reverse Proxy的有Squid、Apache、Lighttpd、Nginx等,后两个轻量级的应用因为其优秀的表现已迅速占领了大量市场,本文只讨论后两者的简单应用(用proxy处理静态文件而把动态文件交给后端的Web服务器来处理)

安装环境

操作系统:Debian4.0r3

Kernel:2.6.18-6-686

软件列表

nginx-0.6.31.tar.gz

lighttpd-1.4.19.tar.gz

安装过程

安装nginx作为反向代理

#tarzxvfnginx-0.6.31.tar.gz

#cdnginx-0.6.31

#./configure--prefix=/usr/local/nginx--with-http_realip_module

#makeinstall

#vi/usr/local/nginx/conf/nginx.conf

location/{

proxy_passhttp://127.0.0.1/;

proxy_redirectoff;

proxy_set_headerHost$host;

proxy_set_headerX-Real-IP$remote_addr;

#proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;;

client_max_body_size10m;

client_body_buffer_size128k;

proxy_connect_timeout90;

proxy_send_timeout90;

proxy_read_timeout90;

proxy_buffer_size4k;

proxy_buffers432k;

proxy_busy_buffers_size64k;

proxy_temp_file_write_size64k;

}

#Staticfileslocation

location~*^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|htm|html)${

root/srv/www/htdocs/;

}

启动nginx

#/usr/local/nginx/sbin/nginx

安装lighttpd作为反向代理

#tarzxvflighttpd-1.4.19.tar.gz

#cdlighttpd-1.4.19

#./configure--prefix=/usr/loca/lighttpd--without-bzip2

#makemakeinstall

#cpdoc/lighttpd.conf/etc/lighttpd.conf

#vi/etc/lighttpd.conf

server.modules=(

"mod_access",

"mod_status",

"mod_proxy",

"mod_accesslog")

server.document-root="/srv/www/htdocs/"

server.errorlog="/var/log/lighttpd/error.log"

status.status-url="/server-status"

$HTTP["url"]!~"\.(js|css|gif|jpg|png|ico|txt|swf|html|htm)$"{

proxy.server=(""=>(

("host"=>"127.0.0.1","port"=>8080)

)

)

}

启动lighttpd

#/usr/local/lighttpd/sbin/lighttpd-f/etc/lighttpd.conf

参考文档

http://www.mysqlperformanceblog.com/2008/06/17/lighttpd-as-reverse-proxy/

http://blog.kovyrin.net/2006/05/18/nginx-as-reverse-proxy/

http://www.mysqlperformanceblog.com/2006/05/21/speedup-your-lamp-stack-with-lighttpd/

http://blog.kovyrin.net/2006/04/17/typical-nginx-configurations/

相关推荐