ITeye博客

linux 下的 Nginx+Mongrel 环境配置

PBFox · 2007-12-17 13:52 · Markdown

Nginx+Mongrel

1.Download Nginx

You can download Nginx in this url( http://nginx.net/) .

The last stable version is nginx-0.5.34

The last development version is nginx-0.6.21

I use nginx-0.5.34

2.Setup Mongrel

gem install mongrel

gem install mongrel_cluster

3.Setup nginx-0.5.34

setup nginx need PCRE first

[root@localhost root]# ftp ftp.csx.cam.ac.uk

Name (ftp.csx.cam.ac.uk:root): anonymous

Password:

ftp> cd pub/software/programming/pcre

ftp> get pcre-7.4.tar.bz2

ftp>quit

[root@localhost root]# tar -jxvf pcre-7.4.tar.bz2

[root@localhost root]# cd pcre-7.4

[root@localhost pcre-7.4]# ./configure

[root@localhost pcre-7.4]# make

[root@localhost pcre-7.4]# wget http://sysoev.ru/nginx/nginx-0.5.34.tar.gz

``[root@localhost pcre-7.4]#tar -zxvf nginx-0.5.34.tar.gz

``[root@localhost pcre-7.4]#cd nginx-0.5.34

``[root@localhost nginx-0.5.34]#./configure –with-pcre=/usr/local/nginx

``[root@localhost nginx-0.5.34]#make && make install

4. Configure nginx

edit /usr/local/nginx/conf/nginx.conf:

user  someuser;
worker_processes  1;

error_log logs/error.log  notice;

pid logs/nginx.pid;

events {
worker_connections  1024;
}

http {
include       conf/mime.types;
default_type  application/octet-stream;

access_log  logs/access.log;

sendfile        on;
tcp_nopush     on;

keepalive_timeout  65;
tcp_nodelay        on;

gzip  on;
gzip_min_length  1100;
gzip_buffers     4 8k;
gzip_types       text/plain;

upstream mongrel {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
}

server {
listen       80;
server_name  localhost;
location / {
proxy_pass http://mongrel;
}

root /home/your/app/path;

access_log  off;
rewrite_log on;

location ~ ^/$ {
if (-f /index.html){
rewrite (.*) /index.html last;
}
proxy_pass  http://mongrel;
proxy_set_header   Host             $host;
}

location / {
if (!-f $request_filename.html) {
proxy_pass  http://mongrel;
}
rewrite (.*) $1.html last;
}

location ~ .html {
root /home/your/app/path;
}

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|mov)$ {
root /home/your/app/path;
}
location / {
proxy_pass  http://mongrel;
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;
}
}
}

5.Start nginx

[root@localhost root]#sudo /usr/local/nginx/sbin/nginx

6.Configure and Start mongrel_cluster

[root@localhost root]#cd /home/your/app/path

[root@localhost root]#sudo mongrel_rails cluster::configure -e development -p 3000 -N 4 -c /home/your/app/path -a 127.0.0.1

[root@localhost root]#sudo mongrel_rails cluster::start

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。