Weitere Ă€hnliche Inhalte Ăhnlich wie Nginx: Accelerate Rails, HTTP Tricks (20) Mehr von Adam Wiggins (8) KĂŒrzlich hochgeladen (20) Nginx: Accelerate Rails, HTTP Tricks7. Apache is the right tool:
âŁmod_php
âŁowning your own server hardware 8. Apache is the right tool:
âŁmod_php
âŁowning your own server hardware
The era now coming to a close. 10. The era now upon us:
âŁRails
âŁcloud computing
Which both work best with proxying. 25. Memcached in front
location / {
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
error_page 404 502 = @myapp;
}
location @myapp {
internal;
proxy_pass http://myapp_mongrels;
} 26. Memcached method filter
location / {
if ($request_method = GET) {
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
error_page 404 502 = @myapp;
break;
}
proxy_pass http://myapp_mongrels;
} 33. Separate concerns:
âŁFilters in your app for
business logic
âŁFilters in your http router
for server infrastructure
âŁFilters in either for
application infrastructure 34. Separate concerns:
âŁFilters in your app for
business logic
âŁFilters in your http router
for server infrastructure
âŁFilters in either for
application infrastructure 39. The Rails solution: before_filter
before_filter :authorize
def authorize
@user = User.find(session[:user_id])
@resource = request.env['REQUEST_URI']
redirect_to '/login' unless @user
redirect_to '/access_denied' unless
@user.can_access(@resource)
end 40. Can we do this without
touching the Rails appâs
code? 45. def authorize
@user = User.find(session[:user_id])
@resource = request.env['REQUEST_URI'] 46. def authorize
@user = User.find(session[:user_id])
@resource = request.env['REQUEST_URI']
static ngx_int_t ngx_heroku_gate_handler
(ngx_http_request_t *req)
{
user = get_logged_in_user(
req->headers_in.cookies);
app_name = get_app_name(
req->headers_in.host->value.data); 50. redirect_to '/access_denied' unless
@user.can_access(@resource)
if (!user_can_access(user, app))
{
redirect_to(req, '/access_denied');
return NGX_HTTP_MOVED_TEMPORARILY;
}
else
{
write_heroku_user_header(req, user);
return NGX_OK;
} 51. #define X_HEROKU_USER quot;X-Heroku-Userquot;
static void write_heroku_user_header
(ngx_http_request_t *r, u_char *user)
{
h = ngx_list_push(
&r->headers_in.headers);
h->hash = 1;
h->key.len = sizeof(X_HEROKU_USER) - 1;
h->key.data = (u_char *) X_HEROKU_USER;
h->value.len = strlen((char *)user);
h->value.data = user;
} 52. The Rails solution: before_filter
before_filter :authorize
def authorize
@user = User.find(session[:user_id])
@resource = request.env['REQUEST_URI']
redirect_to '/login' unless @user
redirect_to '/access_denied' unless
@user.can_access(@resource)
end 53. The Nginx solution: input filter
static ngx_int_t
ngx_heroku_gate_handler(ngx_http_request_t *req)
{
user = get_logged_in_user(req->headers_in.cookies);
app_name = get_app_name(req->headers_in.host->value.data);
if (!user) {
redirect_to(req, '/login');
return NGX_HTTP_MOVED_TEMPORARILY;
}
if (!user_can_access(user, app)) {
redirect_to(req, '/access_denied');
return NGX_HTTP_MOVED_TEMPORARILY;
}
else {
write_heroku_user_header(req, user);
return NGX_OK;
}
} 56. HTTP is the enabling
protocol for the era
of cloud computing