Skip to content

Instantly share code, notes, and snippets.

@kyroskoh
Forked from Globegitter/nginx-latest.sh
Last active December 8, 2015 10:07
Show Gist options
  • Save kyroskoh/8264c93eb45a87613302 to your computer and use it in GitHub Desktop.
Save kyroskoh/8264c93eb45a87613302 to your computer and use it in GitHub Desktop.
Install the latest nginx from source for Ubuntu 14.04
#Downloading OpenSSL:
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
#Extracting files from the downloaded package:
tar -xvzf openssl-1.0.1g.tar.gz
#Configuring OpenSSL:
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
#Compiling OpenSSL:
make
#Installing OpenSSL:
sudo make install_sw
#Download zlib
wget http://zlib.net/zlib-1.2.8.tar.gz
#Extracting files from the downloaded package:
tar -xvzf zlib-1.2.8.tar.gz
#Now, enter the directory where the package is extracted.
cd zlib-1.2.8
#Configuring zlib Library:
./configure --prefix=/usr/local/zlib
#Compiling zlib:
make
#Installing zlib:
sudo make install
#Install libxml2/libxslt
#sudo apt-get install libxslt-dev
#Install GD Lib
#sudo apt-get install libgd2-xpm libgd2-xpm-dev
#Install others necessary lib
#sudo apt-get install wget build-essential php5-gd libgd2-xpm-dev
#Install libatomic
#sudo apt-get install libatomic-ops-dev
#Install the PCRE library needed by nginx
#sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install build-essential libc6 libpcre3 libpcre3-dev libpcrecpp0 libssl0.9.8 libssl-dev zlib1g zlib1g-dev lsb-base openssl libssl-dev libgeoip1 libgeoip-dev google-perftools libgoogle-perftools-dev libperl-dev libgd2-xpm-dev libatomic-ops-dev libxml2-dev libxslt1-dev python-dev
# Automatically instal the latest nginx
wget -O - http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
#Make a backup copy of your current sources.list file
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#Now copy the following repositories to the end of ` /etc/apt/sources.list`
echo "deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list
#If you want to use the 'stable' branch take:
#echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list
#echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list
#update to get the new repository
sudo apt-get update
sudo apt-get install nginx
## Longer way ##
## Manually build and install the latest nginx ##
#Replace by the latest version number found on http://nginx.org/
wget http://nginx.org/download/nginx-1.7.4.tar.gz
tar -xvf nginx-1.7.4.tar.gz
cd nginx-1.7.4
#These flags make sure to put nginx somewhere that is usuall in PATH and to activate the https module
#./configure --sbin-path=/usr/local/sbin --with-http_ssl_module
#./configure --user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --with-rtsig_module --with-select_module --with-poll_module --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cpp_test_module --with-cpu-opt=CPU --with-pcre --with-pcre-jit --with-md5-asm --with-sha1-asm --with-zlib-asm=CPU --with-libatomic --with-debug --with-ld-opt="-Wl,-E"
./configure --user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --with-openssl=/usr/local/openssl --with-zlib=/usr/local/zlib --with-rtsig_module --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cpp_test_module --with-cpu-opt=CPU --with-pcre --with-pcre-jit --with-md5-asm --with-sha1-asm --with-zlib-asm=CPU --with-libatomic --with-debug --with-ld-opt="-Wl,-E"
sudo make
sudo make install
# Download nginx startup script
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
# Move the script to the init.d directory & make executable
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
# Add nginx to the system startup
sudo /usr/sbin/update-rc.d -f nginx defaults
# This automatically adds the nginx.conf from below into /etc/init/nginx.conf
# If something doesn't work, just copy it manually
#sudo wget -O /etc/init/nginx.conf https://gist.githubusercontent.com/Globegitter/685e3739c0f181bda3ec/raw/6ec0def52ed49d29b2f00cae70d28689371d0230/nginx.conf
sudo wget -O /etc/init/nginx.conf https://gist.github.com/kyroskoh/8264c93eb45a87613302/raw/0ecf25a9ed18a6ccb381ea62b54731082c4848e5/nginx.conf
#This will make sure you get the following commands
#sudo service nginx start
#sudo service nginx stop
#sudo service nginx restart
#sudo service nginx status
##Now you can modify your nginx.conf in /usr/local/nginx/conf
#nginx
description "nginx http daemon"
author "Philipp Klose <me@'thisdomain'.de>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/usr/local/sbin/nginx
env PID=/usr/local/nginx/logs/nginx.pid
expect fork
respawn
respawn limit 10 5
#oom never
pre-start script
$DAEMON -t
if [ $? -ne 0 ]
then exit $?
fi
end script
exec $DAEMON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment