Further nginx work

|

A little while ago, I mentioned the web server Nginx, and had planned to do some fooling with it to see how it handled proxying for a mongrel cluster. I had a spare 20 minutes today, and in the time frame I was able to install Nginx, put together a config file, install mongrel and the cluster controller, and put together a simple Rails app for testing. After realizing I had a typo in my config file, it was up and running like a dream. My config files:

mongrel_cluster.yml


1 user: mongrel
2 cwd: /home/pratzsch/apps/demo
3 log_file: log/mongrel.log
4 port: "5001"
5 environment: development
6 group: mongrel
7 address: 127.0.0.1
8 pid_file: /etc/mongrel.pid
9 servers: 3


nginx.conf


1 user www-data;
2 worker_processes 2;
3
4 error_log /var/log/nginx/error.log notice;
5 pid /var/run/nginx.pid;
6
7 events {
8 worker_connections 1024;
9 }
10
11 http {
12 include /etc/nginx/mime.types;
13 default_type application/octet-stream;
14 access_log /var/log/nginx/access.log
15
16 sendfile on;
17 tcp_nopush on;
18
19 keepalive_timeout 65;
20 tcp_nodelay on;
21
22 upstream mongrel {
23 server 127.0.0.1:5001;
24 server 127.0.0.1:5002;
25 server 127.0.0.1:5003;
26 }
27
28 gzip on;
29 gzip_min_length 1100;
30 gzip_buffers 4 8k;
31 gzip_types text/plain;
32
33 server {
34 listen 80;
35 server_name localhost;
36 root /etc/public;
37
38 access_log off;
39 rewrite_log on;
40
41 location ~ ^/$ {
42 if (-f /index.html){
43 rewrite (.*) /index.html last;
44 }
45
46 proxy_pass http://mongrel;
47 }
48
49 location / {
50 if (!-f $request_filename.html) {
51 proxy_pass http://mongrel;
52 }
53
54 rewrite (.*) $1.html last;
55 }
56
57 location ~ .html {
58 root /etc/public;
59 }
60
61 location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xl s|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
62 root /etc/public;
63 }
64
65 location / {
66 proxy_pass http://mongrel;
67 proxy_redirect off;
68 proxy_set_header Host $host;
69 proxy_set_header X-Real-IP $remote_addr;
70 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71 }
72
73 }
74 }

That's all there is to it. The mongrel_cluster_ctl command can seem to be a little tempermental, but one adjusts to it quickly.

This stack in my view beats the pants off of the Apache2.2 solution.

About this Entry

This page contains a single entry by Philip Ratzsch published on February 29, 2008 5:47 PM.

Day of experimenting was the previous entry in this blog.

From the files of "Huh?" is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.