def detect_config_path():
 try:
  proc = subprocess.Popen(['nginx', '-V'], stderr=subprocess.PIPE)
 except OSError:
  error_exit(('Access log file or format was not set and nginx config file cannot be detected. ' + 'Perhaps nginx is not in your PATH?'))
 (stdout, stderr) = proc.communicate()
 version_output = stderr.decode('utf-8')
 conf_path_match = re.search('--conf-path=(\\S*)', version_output)
 if (conf_path_match is not None):
  return conf_path_match.group(1)
 prefix_match = re.search('--prefix=(\\S*)', version_output)
 if (prefix_match is not None):
  return (prefix_match.group(1) + '/conf/nginx.conf')
 return '/etc/nginx/nginx.conf'

def detect_config_path ( ) : try : proc = subprocess . Popen ( [ 'nginx' , '-V' ] , stderr = subprocess . PIPE ) except OSError : error_exit ( ( 'Access log file or format was not set and nginx config file cannot be detected. ' + 'Perhaps nginx is not in your PATH?' ) ) ( stdout , stderr ) = proc . communicate ( ) version_output = stderr . decode ( 'utf-8' ) conf_path_match = re . search ( '--conf-path=(\\S*)' , version_output ) if ( conf_path_match is not None ) : return conf_path_match . group ( 1 ) prefix_match = re . search ( '--prefix=(\\S*)' , version_output ) if ( prefix_match is not None ) : return ( prefix_match . group ( 1 ) + '/conf/nginx.conf' ) return '/etc/nginx/nginx.conf'
get nginx configuration file path based on nginx -v output :return: detected nginx configuration file path .