Commit 504e4e8e authored by shammash's avatar shammash Committed by kiki

Add blog->site map

We want per-blog traffic stats.

Apache noblogs is configured with a single virtualhost, we cannot use the
virtualhost name (%v) for these stats, because everything will appear as
noblogs.org .

We cannot even use the Host header (%{Host}i) because the virtualhost wildcard
configuration allows for bogus blog names (e.g. cavalle55e.noblogs.org instead
of cavallette.noblogs.org).

With this map nginx can lookup a valid blog name (or default to noblogs.org for
invalid names) and pass it to apache with an internal header (e.g.
X-AI-Noblogs-Site ). Apache will then use this header to produce correct stats.
Signed-off-by: shammash's avatarshammash <shammash@autistici.org>
parent 4500d2ec
......@@ -33,13 +33,11 @@ function backend_to_http_endpoint($backend) {
}
// Print the blog -> backend map.
function generate_map() {
function generate_backend_map($blogs) {
global $wpdb;
global $noblogs_master;
$wpdb_hash = &$wpdb->hash_map;
$blogs = get_blogs();
printline('map $http_host $backend_noblogs {');
printline(' default http://' . $noblogs_master . ':82;');
foreach ($blogs as $blog) {
......@@ -53,5 +51,24 @@ function generate_map() {
printline('}');
}
// Print the blog -> site map.
// This is used to send apache the right site name for logging purposes.
function generate_site_map($blogs) {
printline('map $http_host $site_noblogs {');
printline(' default noblogs.org;');
foreach ($blogs as $blog) {
$blog_id = $blog->blog_id;
if ($blog_id == 1)
continue;
printline(' ' . $blog->domain . ' ' . $blog->domain . ';');
}
printline('}');
}
function generate_maps() {
$all_blogs = get_blogs();
generate_backend_map($all_blogs);
generate_site_map($all_blogs);
}
generate_map();
generate_maps();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment