K
K
karpo5182021-07-07 15:12:47
Nginx
karpo518, 2021-07-07 15:12:47

How to apply location directive for all server directives in nginx.conf?

It is necessary to intercept and override calls to the robots.txt file on all hosts. I wrote a rule:

location = /robots.txt {
add_header Content-Type text/plain;
return 200 "User-agent: *\nDisallow: /\n";
}

How can this rule be applied to all hosts without adding it to the server directive for each host?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-07-07
@karabanov

It is necessary to use Asible, Puppet or any other automation tool so that there is no need to write configs manually.
Take out this location in a separate config and make include, while Ansible is not available, you can use sed -i in combination with find to edit configs.
I guess VScode or Sublimetext can batch replace, you can try them...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question