-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnginx.py
51 lines (40 loc) · 1.19 KB
/
nginx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
#coding: utf-8
import config
import utils
import os
import logging
def new_vhost(config_template, params):
utils.new_vhost(config_template, params, httpd="nginx")
def add_proxy_vhost(domain_name):
"""
Proxy-vhost wrapper
"""
new_vhost(
config_template="nginx_proxy.conf",
params={'domain': domain_name}
)
def enable_vhost(domain_name):
utils.enable_vhost(domain_name, httpd="nginx")
def disable_vhost(domain_name):
utils.disable_vhost(domain_name, httpd="nginx")
def delete_vhost(domain_name):
utils.disable_vhost(domain_name, delete=True, httpd="nginx")
def vhost_exists(domain_name):
exists = '%s.conf' % domain_name in os.listdir(config.NGINX_ENABLED_DIR)
return exists
def add_uwsgi_vhost(domain_name, document_root):
"""
uWSGI Vhosts wrapper
"""
if vhost_exists(domain_name):
logging.warning("VirtualHost %s already exists on nginx." + \
"Skipping" % domain_name)
else:
new_vhost(
config_template="nginx_uwsgi.conf",
params={
'domain': domain_name,
'document_root': document_root
}
)