小编use*_*472的帖子

从 Nginx conf 中提取服务器的块和值

我们如何使用 AWK 提取 nginx 服务器块?输入

server { # php/fastcgi
listen       80;
server_name  domain1.com www.domain1.com;
access_log   logs/domain1.access.log  main;
root         html;

location ~ \.php$ {
  fastcgi_pass   127.0.0.1:1025;
}
}
server { # simple reverse-proxy
listen       80;
server_name  domain2.com www.domain2.com;
access_log   logs/domain2.access.log  main;

# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/  {
  root    /var/www/virtual/big.server.com/htdocs;
  expires 30d;
}

# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
  proxy_pass      http://127.0.0.1:8080;
}
}
Run Code Online (Sandbox Code Playgroud)

我们如何匹配所需的值并为每个 server{} 块打印一行?

例如

我需要获取listen|root|server_name 的值。所需的输出是

80 domain1.com www.domain1.com html …
Run Code Online (Sandbox Code Playgroud)

awk text-processing nginx

5
推荐指数
1
解决办法
192
查看次数

标签 统计

awk ×1

nginx ×1

text-processing ×1