Skip to content

Instantly share code, notes, and snippets.

@Kuchitama Kuchitama/
Last active Dec 17, 2015

What would you like to do?
Sample of Fabric task to install Nginx
from fabric.api import env, run, local, sudo, cd
from fabric.contrib.files import exists, upload_template
from fabric.decorators import task
import java_setup
nginx_dir = "nginx-%s" % nginx_version
nginx_url = "" % nginx_dir
install_dir = "/usr/local/nginx"
def target():
env.port = 22
env.user = 'vagrant'
env.password = 'vagrant'
def install_dev_pkg():
sudo("apt-get -y install g++")
sudo("apt-get -y install libpcre3 libpcre3-dev")
def get_nginx():
with cd("/tmp"):
sudo("wget %s" % nginx_url)
sudo("tar xzvf nginx-1.2.8.tar.gz")
with cd(nginx_dir):
sudo("./configure --prefix=%s" % install_dir)
sudo("make install")
def clear():
with cd("/tmp"):
sudo("rm -f %s.tar.gz" % nginx_dir )
sudo("rm -rf %s" % nginx_dir )
def install_nginx():
def upload_conf(target='dev'):
template = 'nginx.tmpl'
conf_path = '%s/conf/nginx.conf' % install_dir
if target == 'prod':
upload_template(template, conf_path, {'worker_processes':2, 'server_name':"product"}, use_sudo=True)
upload_template(template, conf_path, {'worker_processes':1, 'server_name':"develop"}, use_sudo=True)
def start_nginx():
sudo('%s/sbin/nginx' % install_dir)
fab target install_dev_pkg install_nginx upload_conf
#user nobody;
worker_processes %(worker_processes)d;
#pid logs/;
events {
worker_connections 1024;
http {
include mime.types;
default_type application/octet-stream;
log_format main 'remote:$remote_addr\t'
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name %(server_name)s;
location / {
root html;
index index.html index.htm;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.