标题有点长,这算是我第一个写出的Perl程序,主要是服务器太多的网站,而之前的管理工作没有做好,没有做对应的IP和域名对应。
我的nginx主要是用来做前端反向代理的,里面n多的网站。
下面是我的nginx配置文件代码
server {
listen 0.0.0.0:80;
server_name www.com;
location / {
proxy_set_header Host $host;
proxy_pass http://1.1.1.1/;
}
}
这里面,0.0.0.0是用来监听端口对外公开的网站IP
www.com是域名(我没有用到这个地方,因为我的nginx配置文件就是用域名.conf的格式命名的)
1.1.1.1是web服务器的IP,同样这里不需要用到这个东西
下面是Perl代码
my $dir = 'd:\v3';
my $csv = 'd:\v3.csv';
opendir DH, $dir or die 'can not open dir.';
open WFH, ">>",$csv;
foreach $file (readdir DH) {
next if $file eq "." or $file eq "..";
#print $file."\n";
$file =~ m/(.*)\.conf/;
$domain = $1;
open FH, $dir.'\\'.$file or die 'file can not be open.';
while (defined($line = <FH>)) {
chomp $file;
if ($line =~ m/listen\s+(.*):80;/) {
$ip = $1;
}
}
close FH;
print WFH "$domain,$ip\n";
}
closedir DH;
解释一下,其中$dir是存放nginx配置文件的目录,这里我给下载到本地windows电脑了
$csv是要保存到的excel文件(其实是可以用excel打开的逗号分隔文本文件)
PS:我不知道csdn的博客为何不支持perl高亮