Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai
noblogs-wp
Commits
f8790832
Commit
f8790832
authored
Nov 01, 2011
by
Joe Oblivian
Committed by
agata
Jul 01, 2020
Browse files
added the mapping file
parent
c5a25100
Changes
1
Hide whitespace changes
Inline
Side-by-side
wp-nginx-map.php
0 → 100644
View file @
f8790832
<?php
// wp-nginx-map.php
//
// Stampa una mappa delle assegnazioni blog -> backend, per NGINX.
// Load wordpress api.
define
(
'WP_CACHE'
,
false
);
require_once
(
'/opt/noblogs/www/wp-load.php'
);
// Return all blogs.
function
get_blogs
()
{
global
$wpdb
;
$sql
=
"SELECT blog_id, domain FROM
$wpdb->blogs
WHERE deleted = 0 AND archived = '0' ORDER BY domain ASC"
;
$result
=
$wpdb
->
get_results
(
$sql
);
return
(
$result
);
}
function
printline
(
$s
)
{
echo
$s
.
"
\n
"
;
}
function
backend_to_http_endpoint
(
$backend
)
{
if
(
substr
(
$backend
,
0
,
8
)
!=
'backend_'
)
{
error_log
(
'diamine, di questo backend non so che farmene: '
.
$backend
);
return
'localhost:82'
;
}
$id
=
substr
(
$backend
,
8
);
return
'172.16.1.'
.
$id
.
':82'
;
}
// Print the blog -> backend map.
function
generate_map
()
{
global
$wpdb
;
$wpdb_hash
=
&
$wpdb
->
hash_map
;
$blogs
=
get_blogs
();
printline
(
'map $http_host $backend_noblogs {'
);
printline
(
' default http://localhost:82;'
);
foreach
(
$blogs
as
$blog
)
{
$blog_id
=
$blog
->
blog_id
;
$backend_id
=
$wpdb_hash
->
lookup
(
$blog_id
);
$backend_http
=
backend_to_http_endpoint
(
$backend_id
);
printline
(
' '
.
$blog
->
domain
.
' http://'
.
$backend_http
.
';'
);
}
printline
(
'}'
);
}
generate_map
();
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment