生成nginx配置文件,反向代理google
google的ip地址经常改变,所以要用nslookup去更新ip
#!/bin/env php
<?php
define("CONF_PATH", '/usr/local/nginx/conf/hosts');
$google_ips = __DIR__ . "/google_ips.txt"; // 保存IP地址文件
$ngx_cnf = CONF_PATH . "/51open.conf"; // NGINX配置文件
exec("nslookup google.com", $out, $ret);
$start = false;
$ips = [];
foreach($out as $line) {
// answer: 之后的是服务器对应IP
if (false !== strpos($line, "answer:")) {
$start = true;
} else if (!$start) {
continue;
}
preg_match("/Address: ((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.)
{3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))/i", $line, $matches);
if (!empty($matches) && isset($matches[1])) {
$ips[] = $matches[1];
}
}
// 保存的IP地址
if (file_exists($google_ips)) {
$data = file_get_contents($google_ips);
if ($data) {
$arr = unserialize($data);
if (isset($arr['ips']) && date('Ymd', $arr['__logtime'])==date('Ymd')) {
$ips = array_merge($ips, $arr['ips']);
$ips = array_unique($ips);
}
}
}
$data = ['__logtime' => time(), 'ips' => $ips];
file_put_contents($google_ips, serialize($data));
$str = '';
foreach ($ips as $ip) {
$str .= sprintf("\n server %s:80 max_fails=3;", $ip);
}
if (!$str) {
exit;
}
$ngx_tpl = <p> 以上就是生成nginx配置文件,反向代理google的内容,更多相关内容请关注PHP中文网(www.php.cn)!<br></p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill11126" title="Google Workspace CLI"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20d79f23518.jpg" alt="Google Workspace CLI" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill11126" title="Google Workspace CLI" class="overflowclass">Google Workspace CLI</a>
<p class="overflowclass">使用 `gw` CLI 与 Google Workspace(Drive、Docs、Sheets)交互。当需要浏览、读取、创建、搜索或管理 Google Drive 中的文件时使用。</p>
</div>
<a rel="nofollow" href="/xiazai/skill11126" title="Google Workspace CLI" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><p>
</p>










