利用perl提取web配置檔案中的域名對應的路徑

餘二五發表於2017-11-17
server 

                { 

                                listen        80; 

                                server_name www.mcshell.org mcshell.org; 

                                index    index.php index.html index.htm; 

                                root    /data0/web/mcshell; 

                                error_page 404 =http://www.mcshell.org; 

if (!-f $request_filename){ 

set $rule_0 1$rule_0; 



if (!-d $request_filename){ 

set $rule_0 2$rule_0; 



if ($rule_0 = “21”){ 

rewrite ^/(.*)?*$ /index.php?_route_=$1 last; 




if ($host != `www.mcshell.org` ) { 

rewrite ^/(.*)$ http://www.mcshell.org/$1 permanent; 



.. 

..
現在要求提取出www.mcshell.org  mcshell.org    /data0/mcshell
這樣的對應方式
程式碼如下
#!/usr/bin/perl 

while(<>){ 

chomp; 

if(/server_names(.*);/){ 

print “$1 “; 

$paths=<>; 

(undef,undef,undef,undef,$server )= split /s+/,$paths; #填充不需要的行 

$pathss=<>; 


(undef,undef,$servers )= split /s+/,$pathss; 


print “$servers
“; 




本文轉自 mcshell 51CTO部落格,原文連結:http://blog.51cto.com/mcshell/480852,如需轉載請自行聯絡原作者


相關文章