Commit d5398d0c authored by shammash's avatar shammash Committed by agata

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 .

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

With this map nginx can lookup a valid blog name (or default to 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 <>
parent e2ab8b14
......@@ -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() {
// 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;');
foreach ($blogs as $blog) {
$blog_id = $blog->blog_id;
if ($blog_id == 1)
printline(' ' . $blog->domain . ' ' . $blog->domain . ';');
function generate_maps() {
$all_blogs = get_blogs();
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