for trafficserver i am using a tiny webservice which is parsing a via cronjob made copy of httpd-vhosts and give back a php-serialized array for each origin server which "ServerName" and "ServerAlias" are valid
with this infos i write the complete "remap.conf" and and" hosts.dnsmasq" for dnsmasq and if there are changes restarts trafficserver see attached "trafficserver.txt" which is the cron-php-script with obfuscated servernames/IP's final goal is to decide simply with the DNS if a domain is served directly by the origin-server or going via reverse-proxy without need to care about trafficservers configuration _______________________________ this way traffic-server ends in mapping like below and "/etc/hosts.dnsmasq" is the key to have on the proxy a DNS on localhost pointing to the IP of the origin server while the real DNS is not touched map http://www.rhsoft.net http://www.rhsoft.net reverse_map http://www.rhsoft.net http://www.rhsoft.net _______________________________ Am 15.08.2012 06:19, schrieb adi.siswanto: > sorry, question again, I found weird habit > after using ATS : > - map foo.bar.com --> bar.com/foo --> OK > - map xyz.com --> foo.bar.com --> OK > > but when I access xyz.com/abc it won't go to bar.com/foo/abc, but > it's always going to xyz.com/foo/abc. Any suggestion how to solve it? > > my remap.conf (where x.x.x.x is bar.com) > map / http://x.x.x.x:8001 > map xyz.com http://x.x.x.x:8001/foo > > regards > > On Sat, 2012-08-11 at 13:39 +0700, adi.siswanto wrote: >> thanks Leif, it works charmly with this >> map / http://bar.com:8001/ >> >> regards >> >> On Fri, 2012-08-10 at 14:02 -0600, Leif Hedstrom wrote: >>> On 08/09/2012 09:02 AM, adi.siswanto wrote: >>>> currently I only tried for >>>> map http://*.bar.com/ http://bar.com:8001/* >>>> reverse_map http://bar.com:8001/* http://*.bar.com/ >>>> >>> >>> This is not valid syntax. Read the docs, or the example from the default >>> remap.config. And yes, if you really want to match on *.bar.com, you >>> should either use regex map, or map on the wildcard (/). E.g. the >>> following would probably do what you want (assuming you only have bar.com): >>> >>> map / http://bar.com:8001 >>> >>> >>> -- leif >>> >> >> >> Gunakan I-Pay untuk pembelian voucher game online, digital content, >> full-track dan lainnnya. Topup I-pay dapat menggunakan Transfer bank >> ,internet banking. Info lengkap I-Pay klik https://ipay.indosatm2.com/ >> >> Disclaimer >> >> This is an e-mail from PT Indosat Mega Media intended solely for the named >> addresse(s). It is confidential and may contain legally privileged >> information. Therefore, any unauthorized use, disclosure or copying of this >> information is strictly prohibited. >> PT Indosat Mega Media does not accept liability for any email loss or files >> damage. > > > Gunakan I-Pay untuk pembelian voucher game online, digital content, > full-track dan lainnnya. Topup I-pay dapat menggunakan Transfer bank > ,internet banking. Info lengkap I-Pay klik https://ipay.indosatm2.com/ > > Disclaimer > > This is an e-mail from PT Indosat Mega Media intended solely for the named > addresse(s). It is confidential and may contain legally privileged > information. Therefore, any unauthorized use, disclosure or copying of this > information is strictly prohibited. > PT Indosat Mega Media does not accept liability for any email loss or files > damage. > -- Reindl Harald the lounge interactive design GmbH A-1060 Vienna, Hofmühlgasse 17 CTO / CISO / Software-Development p: +43 (1) 595 3999 33, m: +43 (676) 40 221 40 icq: 154546673, http://www.thelounge.net/ http://www.thelounge.net/signature.asc.what.htm
#!/usr/bin/php
<?php
$server_list = array
(
'origin1' => 'ip.of.or.1',
'origin2' => 'ip.of.or.2',
);
$config_file_dns = '/etc/hosts.dnsmasq';
$config_file_proxy = '/etc/trafficserver/remap.config';
$restart_dns = '/bin/systemctl restart dnsmasq.service';
$restart_proxy = '/bin/systemctl restart trafficserver.service';
foreach($server_list as $srv_name=>$srv_ip)
{
$dyn_var = 'domains_' . $srv_name;
$$dyn_var =
@file_get_contents('https://webservicehost/trafficserver-webservice.php?origin_server='
. $srv_name);
if(!empty($$dyn_var))
{
$$dyn_var = unserialize($$dyn_var);
if(!array($$dyn_var))
{
exit('Trafficserver: error while request domainlist "' . $srv_name . '"');
}
}
else
{
exit('Trafficserver: error while request domainlist "' . $srv_name . '"');
}
}
$config_dns_new = '';
$host_name_done = array();
foreach($server_list as $srv_name=>$srv_ip)
{
$dyn_var = 'domains_' . $srv_name;
foreach($$dyn_var as $host_name)
{
$host_name = trim($host_name);
if(!empty($host_name))
{
if(!in_array($host_name, $host_name_done) && strpos($host_name, '.') !==
false)
{
$config_dns_new .= $srv_ip . ' ' . $host_name . "\n";
$host_name_done[] = $host_name;
}
}
}
}
$config_proxy_new = '';
$config_proxy_new .= "\n";
$host_name_done = array();
foreach($server_list as $srv_name=>$srv_ip)
{
$dyn_var = 'domains_' . $srv_name;
foreach($$dyn_var as $host_name)
{
$host_name = trim($host_name);
if(!empty($host_name))
{
if(!in_array($host_name, $host_name_done))
{
$config_proxy_new .= 'map http://' . $host_name . ' http://' . $host_name
. "\n";
$config_proxy_new .= 'reverse_map http://' . $host_name . ' http://' .
$host_name . "\n";
$config_proxy_new .= "\n";
$host_name_done[] = $host_name;
}
}
}
}
$config_dns_old = file_get_contents($config_file_dns);
if($config_dns_old != $config_dns_new && trim($config_dns_new) != '')
{
echo $config_file_dns . "\n";
echo '-------------------------------------------------------------' . "\n";
$old_tmp = '/tmp/trafficserver_' . sha1($config_dns_old . microtime()) .
'.conf';
$new_tmp = '/tmp/trafficserver_' . sha1($config_dns_new . microtime()) .
'.conf';
file_put_contents($old_tmp, $config_dns_old);
file_put_contents($new_tmp, $config_dns_new);
$diff_command = '/usr/bin/diff --ignore-case --ignore-blank-lines
--ignore-space-change --minimal -b -w ' . escapeshellarg($old_tmp) . ' ' .
escapeshellarg($new_tmp);
ob_start();
passthru($diff_command);
unlink($old_tmp);
unlink($new_tmp);
$diff_array = explode("\n", ob_get_clean());
$diff_output = '';
$first = 0;
foreach($diff_array as $diff_line)
{
if($first == 0)
{
$first = 1;
}
else
{
$diff_line = trim($diff_line);
if($diff_line != '>')
{
$diff_output .= ' ' . $diff_line . "\n";
}
}
}
echo $diff_output;
echo "\n";
flush();
file_put_contents($config_file_dns, $config_dns_new);
passthru($restart_dns);
}
elseif(trim($config_dns_new) == '')
{
exit('ERROR: ' . $config_file_dns . ' empty' . "\n");
}
$config_proxy_old = file_get_contents($config_file_proxy);
if($config_proxy_old != $config_proxy_new && trim($config_proxy_new) != '')
{
echo $config_file_proxy . "\n";
echo '-------------------------------------------------------------' . "\n";
$old_tmp = '/tmp/trafficserver_' . sha1($config_proxy_old . microtime()) .
'.conf';
$new_tmp = '/tmp/trafficserver_' . sha1($config_proxy_new . microtime()) .
'.conf';
file_put_contents($old_tmp, $config_proxy_old);
file_put_contents($new_tmp, $config_proxy_new);
$diff_command = '/usr/bin/diff --ignore-case --ignore-blank-lines
--ignore-space-change --minimal -b -w ' . escapeshellarg($old_tmp) . ' ' .
escapeshellarg($new_tmp);
ob_start();
passthru($diff_command);
unlink($old_tmp);
unlink($new_tmp);
$diff_array = explode("\n", ob_get_clean());
$diff_output = '';
$first = 0;
foreach($diff_array as $diff_line)
{
if($first == 0)
{
$first = 1;
}
else
{
$diff_line = trim($diff_line);
if($diff_line != '>')
{
$diff_output .= ' ' . $diff_line . "\n";
}
}
}
echo $diff_output;
echo "\n";
flush();
file_put_contents($config_file_proxy, $config_proxy_new);
passthru($restart_proxy);
}
elseif(trim($config_proxy_new) == '')
{
exit('ERROR: ' . $config_file_proxy . ' empty' . "\n");
}
?>
signature.asc
Description: OpenPGP digital signature
