Skip to content

Instantly share code, notes, and snippets.

@shuxiao9058
Forked from abola/nginx-install.sh
Created August 22, 2018 10:25
Show Gist options
  • Save shuxiao9058/f734efad192d132b1e9592ab0619b16f to your computer and use it in GitHub Desktop.
Save shuxiao9058/f734efad192d132b1e9592ab0619b16f to your computer and use it in GitHub Desktop.
Nginx install step with CentOS 6.7 min
#!/bin/sh
# required install
yum -y groupinstall 'Development Tools'
yum -y install wget patch git
yum -y install pcre-devel zlib-devel openssl-devel
# nginx download
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
# third-party module download & patch
git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
git clone https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng.git
git clone https://github.com/gnosek/nginx-upstream-fair.git
patch -p1 < ./nginx_upstream_check_module/check_1.7.5+.patch
patch -p0 ./nginx-sticky-module-ng/ngx_http_sticky_module.c < ./nginx_upstream_check_module/nginx-sticky-module.patch
patch -p2 ./nginx-upstream-fair/ngx_http_upstream_fair_module.c < ./nginx_upstream_check_module/upstream_fair.patch
# build source
./configure \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--error-log-path=/var/log/nginx/error_log \
--http-log-path=/var/log/nginx/access_log \
--add-module=./nginx_upstream_check_module \
--add-module=./nginx-upstream-fair \
--add-module=./nginx-sticky-module-ng
make
make install
# set Nginx as service
curl https://gist.githubusercontent.com/abola/024b145e3ff5283bdb0b/raw/d785ae7b4a7f98001bf63f64cb80b690974c72d4/nginx > /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig nginx on
# start Nginx server as service
service nginx start
# restart Nginx service
service nginx stop && sleep 1 && service nginx start
# (*optional) add server status report at port 8888
mkdir -p /var/www/srv1
mkdir -p /var/www/srv2
touch /var/www/srv1/alive.txt
touch /var/www/srv2/alive.txt
echo "http{server{listen 81;server_name localhost;location / {root /var/www/srv1;}}server{listen 82;server_name localhost;location / {root /var/www/srv2;}}}" >> /etc/nginx/nginx.conf
echo "http{upstream loadbalance {server localhost:81;server localhost:82;check interval=5000 rise=2 fall=5 timeout=1000 type=http;check_http_send \"GET /alive.txt HTTP/1.0\r\n\r\n\";} server{listen 8888;server_name localhost;location /status {check_status;}}}" >> /etc/nginx/nginx.conf
# (*optional) get status resule
curl http://localhost:8888/status?format=csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment