added option to specify the ip to listen on. If the option is missing, nginx will be listening on all ips.

This commit is contained in:
Joachim Lusiardi 2015-01-07 15:06:15 +01:00
parent f7713d84a3
commit fa01646eb4
1 changed files with 8 additions and 4 deletions

View File

@ -10,7 +10,7 @@ from string import Template
target_path="/tmp/nginx"
pid_file="/run/nginx.pid"
non_location_template = """server {
listen 80;
listen $listen;
server_name $name;
location / {
proxy_set_header X-Real-IP $$remote_addr;
@ -22,7 +22,7 @@ non_location_template = """server {
"""
location_template="""server {
listen 80;
listen $listen;
server_name $name;
location / {
return 301 $$scheme://$name/$location;
@ -102,14 +102,18 @@ def handle_event(event):
if 'location' in proxy_data:
location = proxy_data['location']
listen ='*:80'
if 'ip' in proxy_data:
listen = proxy_data['ip']+':80'
print('writing /tmp/nginx/proxy_'+container_id)
with open('/tmp/nginx/proxy_'+container_id, 'w') as file:
if location == '':
s = Template(non_location_template)
file.write(s.substitute(name=server_name,ip=ip,port=port))
file.write(s.substitute(name=server_name,ip=ip,port=port,listen=listen))
else:
s = Template(location_template)
file.write(s.substitute(name=server_name,ip=ip,port=port,location=location))
file.write(s.substitute(name=server_name,ip=ip,port=port,listen=listen,location=location))
print('HUPing nginx')
os.kill(pid, signal.SIGHUP)