Esempio n. 1
0
def install_nginx(version=None, remove_default=True):
    '''
    Install nginx as a webserver or reverse proxy

    :param str version: the version of nginx you want to have installed if it's
        a different version than the repository version. E.g. 1.0.4
    '''
    # install from the repository to get stable version and initial config
    install('nginx')
    default_site = '/etc/nginx/sites-enabled/default'
    if remove_default and exists(default_site):
        sudo('rm %s' % default_site)
        restart('nginx')
    # if a version is specified, install that and overwrite the repo version
    if version:
        stop('nginx')
        run('mkdir -p src')
        with cd('src'):
            run('wget http://nginx.org/download/nginx-%s.tar.gz' % version)
            run('tar xf nginx-%s.tar.gz' % version)
            # requirements for nginx
            install('build-essential', 'libc6', 'libpcre3', 'libpcre3-dev',
                    'libpcrecpp0', 'libssl0.9.8', 'libssl-dev', 'zlib1g',
                    'zlib1g-dev', 'lsb-base')
            with cd('nginx-%s' % version):
                run('''./configure --with-http_ssl_module \\
                       --with-sha1=/usr/lib \\
                       --with-http_gzip_static_module \\
                       --with-http_stub_status_module \\
                       --without-http_fastcgi_module \\
                       --sbin-path=/usr/sbin \\
                       --conf-path=/etc/nginx/nginx.conf \\
                       --prefix=/etc/nginx \\
                       --error-log-path=/var/log/nginx/error.log \\
                       ''')
                run('make')
                sudo('make install')
        start('nginx')