1

I have tens of sites listening on multiple ip addresses at nginx. For example,

server {listen 172.16.33.1:80; server_name a.com}
..
server {listen 172.16.33.1:80; server_name f.com}
server {listen 172.16.33.2:80; server_name d.com}
..
server {listen 172.16.33.2:80; server_name r.com}
server {listen 172.16.33.1:443; server_name aa.com}
server {listen 172.16.33.2:443; server_name bb.com}
server {listen 172.16.33.3:443; server_name cc.com}

Is there any possible way to set listen ips to variables? Like "$ip1=172.16.33.1; $ip2=172.16.33.2;" and then change conf to

server {listen $ip1:443; server_name aa.com}
server {listen $ip2:443; server_name bb.com}

I know about search and replace in every text editor, but it would be more easy when you change listen ip once to make effect on all corresponding sites.

1 Answers1

1

Nginx by default don't support variables for the listen directive.

But another approach to dynamically configure Nginx is by using ansible

Here you can check the roles: https://galaxy.ansible.com/nginxinc/

And here you can read more about ansible: https://www.ansible.com/

nbari
  • 25,603
  • 10
  • 76
  • 131