---
title: "Fedora Core 6 上安裝 beast (3)"
author: "thegiive"
date: "2007-08-22T09:41:15Z"
tags: []
slug: "fedora-core-6-beast-3"
draft: false
lastmod: "2007-08-22T09:41:15Z"
id: 115415
url: "https://thegiive.iteye.com/blog/115415"
---

覺得 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 =&gt; 75...  
但當然以我測試機的超低流量來看，就算直接用 mongrel 應該也是瞬間反應…