作者godfat (godfat 真常)
看板Ruby
标题[心得] Fedora Core 6 上安装 beast (3)
时间Wed Aug 22 17:27:34 2007
觉得 pound + lighttpd 太麻烦吗?又翻到一个应该不错的选择,
是一个俄国人写的 http server, 也具有 reverse proxy 和
load balancing 的能力。
godfat ~ 3.2$ port info nginx
nginx 0.5.29, www/nginx (Variants: universal, dav, flv, mail, ssl)
http://nginx.net/
Nginx ("engine x") is a high-performance HTTP(S) server and reverse proxy,
as well as an IMAP/POP3 proxy server. Nginx was written by Igor Sysoev for
Rambler.ru, Russia's second-most visited website, where it has been running
in production for over two and a half years. Igor has released the source
code under a BSD-like license. Although still in beta, Nginx is known for
its stability, rich feature set, simple configuration, and low resource
consumption.
这个字实在是很难记…不过讨论翻来翻去,他 serve static file 的效能和
lighttpd 在伯仲之间,而 load balancing 是正常可用的。所以与其使用
pound + lighttpd, 单用 nginx 可以简化一些流程。我想缺点就是设定上
还是比 pound 复杂些,不过我个人是觉得比 lighttpd 简单了。另外 nginx
好像没有 windows 版,而 pound 和 lighttpd 都有 windows 版,
我想这对某些情况可能也是个考量吧?
虽然之前因为英文文件太少所以不太流行,但最近似乎还算有蛮多人推荐的,
而且这在俄国好像还蛮广泛被使用的,试试应该无妨。
sudo yum install nginx
跟 lighttpd 一样,一起丢到 beast 目录下比较容易管理。
cp /etc/nginx/nginx.conf \
/home/YOUR_NAME/projects/beast/stable-1.0/config/nginx.conf
cp /etc/nginx/mime.types \
/home/YOUR_NAME/projects/beast/stable-1.0/config/mime.types
前者是 config 档,後者是 mime-type 设定档,会被 include 进去。
nano config/nginx.conf
=======================
user YOUR_NAME YOUR_NAME;
worker_processes 1;
pid /home/YOUR_NAME/projects/beast/stable-1.0/tmp/pids/nginx.pid;
error_log /home/YOUR_NAME/projects/beast/stable-1.0/log/nginx_error.log;
events {
worker_connections 1024;
}
http {
include /home/YOUR_NAME/projects/beast/stable-1.0/config/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /home/YOUR_NAME/projects/beast/stable-1.0/log/nginx_access.log \
main;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain text/html text/xhtml text/css text/javascript;
upstream mongrel {
server 127.0.0.1:2000;
server 127.0.0.1:2001;
server 127.0.0.1:2002;
}
server {
listen 80;
server_name localhost;
location ~ ^/(images|javascripts|stylesheets)/ {
root /home/YOUR_NAME/projects/beast/stable-1.0/public
expires 30d;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass
http://mongrel;
}
}
}
=======================
其实还有一大堆设定我省略掉了,可以自己上官网或 google 找其他的设定。
启动:
sudo nginx -c config/nginx.conf
关闭:
sudo kill `cat tmp/pids/nginx.pid`
我用这个去跑 YSlow, 应该是设定的关系,分数从 62 => 75...
但当然以我测试机的超低流量来看,就算直接用 mongrel 应该也是瞬间反应…
==
测试机:
http://ym.godfat.tw
--
Nobody can take anything away from him.
Nor can anyone give anything to him.
What came from the sea,
has returned to the sea.
Chrono Cross
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.218.90.242