petrel919 发表于 2018-11-15 09:56:19

自动安装nginx 不同版本

#!/usr/bin/python  
# conding:utf8
  

  
from optparse import OptionParser
  
import re
  
import pycurl
  
import StringIO
  
import sys
  
import urllib2
  
import subprocess
  
import threading
  
import os
  
from optparse import OptionParser
  

  
def parse_url(url):
  c = pycurl.Curl()
  b = StringIO.StringIO()
  c.setopt(c.URL, url)
  c.setopt(pycurl.FOLLOWLOCATION, 1)
  c.setopt(c.WRITEFUNCTION, b.write)
  c.perform()
  c.setopt(c.CONNECTTIMEOUT, 5)
  c.setopt(c.TIMEOUT, 5)
  status = c.getinfo(pycurl.HTTP_CODE)
  if status == 200:
  content = b.getvalue()
  return content
  c.close()
  b.close()
  

  
def nginx_download(version):
  nginx_package = "nginx-%s.tar.gz" % (version)
  url = "http://nginx.org/download/%s" % (nginx_package)
  if not os.path.exists("/root/%s" % (nginx_package)):
  print "download %s ..." % (nginx_package)
  f = urllib2.urlopen(url)
  data = f.read()
  with open("/root/%s" % (nginx_package), "wb") as nginx:
  nginx.write(data)
  print "download success"
  return 0
  

  
def list_nginx():
  url = "http://nginx.org/download/"
  content = parse_url(url)
  version = []
  p = re.compile(r'>(nginx-(.*?).tar.gz)
页: [1]
查看完整版本: 自动安装nginx 不同版本