def restart(): print('Restarting nginx:', end=' ') try: sudo.nginx('-p', CONF_DIR, '-c', os.path.join(CONF_DIR, 'nginx.conf'), '-s', 'stop') except ErrorReturnCode: pass # ignore finally: try: sh.nginx('-p', CONF_DIR, '-c', os.path.join(CONF_DIR, 'nginx.conf')) except ErrorReturnCode: print(colored('failed', 'red', attrs=['bold']) + '.') else: print(colored('nginx', 'green', attrs=['bold']) + '.')
def save(self): if self.name and self.ip: os.chdir('/home/fohnwind/ng/conf/') filename = self.name + "." + DefaultConfig.SITE_NAME + ".conf" fp = open(filename, 'w') conf = Template(filename="ngconf.default").render(ip=self.ip, name=self.name) print >> fp, conf fp.close() nginx("-s","reload") return True return False
def Proxy(self): ngx_user_conf = os.path.join(Config.PROXY_DIR, self.name) + '.conf' ngx_conf_content = r'''server { listen 80; server_name %s; index index.htm index.html index.php index.jsp; location / { proxy_pass http://%s:%s/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }''' %(self.dn, self.ip, int(self.port)) with open(ngx_user_conf, 'w') as f: f.write(ngx_conf_content) from sh import nginx nginx('-s', 'reload')
def Proxy(self): ngx_user_conf = os.path.join(Config.PROXY_DIR, self.name) + '.conf' ngx_conf_content = r'''server { listen 80; server_name %s; index index.htm index.html index.php index.jsp; location / { proxy_pass http://%s:%s/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }''' % (self.dn, self.ip, int(self.port)) with open(ngx_user_conf, 'w') as f: f.write(ngx_conf_content) from sh import nginx nginx('-s', 'reload')
def stop(self): self.print("Stopping server") sh.nginx("-s", 'stop')
def reload(self): self.print("Reloading server") sh.nginx("-s", 'reload')
def start(self): self.print("Starting server") sh.nginx("-g", 'daemon off;')