自动安装nginx 不同版本

简介:
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/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):
     =  pycurl.Curl()
     =  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)
         =  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  =  []
     =  re. compile (r '>(nginx-(.*?).tar.gz)<' )
     for  in  p.finditer(content):
         version.append(m.group( 2 )) 
     return  version[: - 21 : - 1 ]
 
def  install_nginx(version):
     nginx_package  =  "nginx-%s.tar.gz"  %  (version)
     lua_module  =  "https://github.com/openresty/lua-nginx-module.git"
     echo_module  =  "https://github.com/openresty/echo-nginx-module.git"
     check_module  =  "https://github.com/yaoweibin/nginx_upstream_check_module"
     
     packages  =  [ 'openssl-devel' 'zlib-devel' 'pcre-devel' 'lua-devel' 'gcc' ]
     
     for  package  in  packages:
         =  subprocess.call( "rpm -qa | grep '%s'"  %  (package), shell = True )
        print  p
         if  p ! =  0 :
             p1  =  subprocess.call( "yum install %s -y"  %  (package), shell = True )
         if  p1  = =  0 :
             print  "yum install %s success"  %  (package)
 
     if  os.path.exists( "/root" ):
             subprocess.call( "cd /root" , shell = True )
 
         if  not  os.path.exists( "/root/lua-nginx-module" ): 
             print  "git lua-nginx-module ..."
             =  subprocess.call( "git clone %s"  %  (lua_module), shell = True )
             if  = =  0 :
                 print  "git lua-nginx-module success"
 
         if  not  os.path.exists( "/root/echo-nginx-module" ):
             print  "git echo-nginx-module ..."
             =  subprocess.call( "git clone %s"  %  (echo_module), shell = True )
             if  = =  0 :
                 print  "git echo-nginx-module success"
 
         if  not  os.path.exists( "/root/nginx_upstream_check_module" ):  
             print  "git nginx_upstream_check_module ..."
             =  subprocess.call( "git clone %s"  %  (check_module), shell = True )
             if  = =  0 :
                 print  "git nginx_upstream_check_module success"
         
         if  not  os.path.exists( "/root/nginx-%s"  %  (version)):
             print  "tar %s ..."  %  (nginx_package)
             subprocess.call( "tar -xzvf %s"  %  (nginx_package), shell = True )
             print  "tar success"
 
         print  "install %s ..."  %  (nginx_package)
         =  subprocess.call( "cd /root/nginx-%s;./configure --prefix=/usr/local/nginx-%s --with-http_ssl_module --with-http_gzip_static_module --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --add-module=/root/lua-nginx-module --add-module=/root/echo-nginx-module"  %  (version, version), shell = True )
         if  = =  0 :
             =  subprocess.call( "cd /root/nginx-%s;make"  %  (version), shell = True )
             if  = =  0 :
                 subprocess.call( "cd /root/nginx-%s;make install"  %  (version), shell = True )
                 print  "install %s success"  %  (nginx_package)
 
def  main():
     parser  =  OptionParser()
     parser.add_option( "-l" "--list" , action = "store_true" , dest = "list" help = "list nginx version" )
     parser.add_option( "-i" "--version" , action = "store" , dest = "version" help = "install nginx version" )
     (options, args)  =  parser.parse_args()
     if  options. list :
         for  version  in  list_nginx():
             print  version
     elif  options.version:
         if  options.version  in  list_nginx():
             if  nginx_download(options.version)  = =  0 :
                 install_nginx(options.version)
     
if  __name__  = =  '__main__' :
     main() 









本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1624960,如需转载请自行联系原作者
目录
相关文章
|
Ubuntu 网络协议 应用服务中间件
在 Ubuntu 上安装 Nginx
在 Ubuntu 上安装和配置 Nginx 非常简单。首先更新系统包,然后通过 `apt` 安装 Nginx,检查服务状态并配置防火墙规则。访问服务器 IP 测试是否成功显示默认页面。还可管理服务、创建虚拟主机及排查常见问题,适合新手快速上手部署高性能 Web 服务。
1391 0
|
应用服务中间件 Linux nginx
【Azure App Service】基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?
基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?Web App Linux 默认使用的 Nginx 版本是由平台预定义的,无法更改这个版本。
377 77
|
前端开发 应用服务中间件 nginx
docker安装nginx,前端项目运行
通过上述步骤,你可以轻松地在Docker中部署Nginx并运行前端项目。这种方法不仅简化了部署流程,还确保了环境的一致性,提高了开发和运维的效率。确保按步骤操作,并根据项目的具体需求进行相应的配置调整。
1514 25
|
应用服务中间件 网络安全 nginx
轻松上手Nginx Proxy Manager:安装、配置与实战
Nginx Proxy Manager (NPM) 是一款基于 Nginx 的反向代理管理工具,提供直观的 Web 界面,方便用户配置和管理反向代理、SSL 证书等。本文档介绍了 NPM 的安装步骤,包括 Docker 和 Docker Compose 的安装、Docker Compose 文件的创建与配置、启动服务、访问 Web 管理界面、基本使用方法以及如何申请和配置 SSL 证书,帮助用户快速上手 NPM。
14757 1
|
应用服务中间件 Linux nginx
Mac os 安装 nginx 教程(success)
这篇文章是关于如何在Mac OS系统上使用Homebrew安装nginx及其依赖,并解决安装过程中可能出现的权限问题。
2339 0
Mac os 安装 nginx 教程(success)
|
负载均衡 应用服务中间件 Linux
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
这篇博客文章详细介绍了Nginx的下载、安装、配置以及使用,包括正向代理、反向代理、负载均衡、动静分离等高级功能,并通过具体实例讲解了如何进行配置。
751 5
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
|
负载均衡 算法 应用服务中间件
Nginx安装及配置详解
Nginx安装及配置详解
|
应用服务中间件 程序员 开发工具
mac下安装nginx
mac下安装nginx
|
应用服务中间件 Linux nginx
CentOS7安装Nginx
CentOS7安装Nginx
|
Ubuntu 搜索推荐 应用服务中间件
Nginx安装与使用
Nginx安装与使用