Skip to content

Instantly share code, notes, and snippets.

@chixq
Last active January 3, 2016 07:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chixq/8431377 to your computer and use it in GitHub Desktop.
Nginx installer script (including patch for url_hash)
#!/bin/bash
#####################################################
# 1. Download nginx source (not using PM in order to use 3rd-party patch)
# 2. Hack with url_hash (optional)
# 3. Compile and make install with predefined path
# 4. Sync the nginx.conf with gist
# 5. Start nginx
#####################################################
# Nginx Defaults
NGINX_URL="http://www.nginx.org/download/nginx-1.5.2.tar.gz"
NGINX_TGZ="nginx-1.5.2.tar.gz"
NGINX_DIR="nginx-1.5.2"
PATCH_URL="http://wiki.nginx.org/images/1/11/Nginx_upstream_hash-0.3.1.tar.gz"
PATCH_TGZ="Nginx_upstream_hash-0.3.1.tar.gz"
PATCH_DIR="nginx_upstream_hash-0.3.1"
# Download and unpack Nginx
wget -q $NGINX_URL
wget -q $PATCH_URL
tar vxf $NGINX_TGZ
tar vxf $PATCH_TGZ
# Move into the directory and patch
cd $NGINX_DIR
patch -p0 < ../$PATCH_DIR/nginx.patch
# Build and Install
./configure --prefix=/opt/nginx --with-http_gzip_static_module --pid-path=/var/run --with-pcre --with-http_ssl_module --with-http_image_filter_module --add-module=../$PATCH_DIR
make
make install
# Download the config from gist, conf with preset backend server and ssl.
curl -sL https://gist.github.com/chixq/8431346/raw/4c34c2eac5be071736831a277fb17deafcc4baa5/nginx.conf > /opt/nginx/conf/nginx.conf
# Create the log dir
mkdir /var/log/nginx
# Start Nginx
/opt/nginx/sbin/nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment