code]# Defining mongrel cluster
upstream mongrel {
server 127.0.0.1:8150;
server 127.0.0.1:8151;
server 127.0.0.1:8152;
server 127.0.0.1:8153;
}
# Defining web server
server {
listen 216.86.155.55:80;
server_name domain.tld;
# All dynamic requests will go here
location / {
default_type text/html;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
# All POST requests go to mongrel directly
if ($request_method = POST) {
proxy_pass http://mongrel;
break;
}
# Say nginx to try to fetch some key from memcache: "yourproject:Action:$uri", like ""yourproject:Action:/posts/1"
set $memcached_key "yourproject:Action:$uri";
memcached_pass localhost:11211;
proxy_intercept_errors on;
# If no info would be found in memcache or memecache would be dead, go to /fallback location
error_page 404 502 = /fallback$uri;
}
# This location would be called only if main location failed to serve request
location /fallback/ {
# This means, that we can't get to this location from outside - only by internal redirect
internal;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
# Pass request to mongrel
proxy_pass http://mongrel/;
}
# Some static location to serve directly w/o bothering backend
# (here should be more of such static paths or one regex-based location)
location /images/ {
root /rails/lazygeeks/public/current/public;
}
}[/code]
Notice: This config is not optimal, but it shows us what we’re going to do here.
So, what do can we see above: ng
# This location would be called only from SSI tags
location /dynamic {
# This means, that we can't get to this location from outside - only by internal redirect
internal;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
# Pass request to mongrel
proxy_pass http://mongrel;
}
4. Replace dynamic parts in your templates with
<!--# include virtual="full_url_to_your_partial" -->
where full_url_to_your_partial is something like http://domain.tld/dynamic/login_field. Code: [Select]