Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active January 7, 2020 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/669c8cda17cb9d7cbc05111ebfb6694e to your computer and use it in GitHub Desktop.
Save miguelmota/669c8cda17cb9d7cbc05111ebfb6694e to your computer and use it in GitHub Desktop.
Nginx install headers-more-nginx-module in Amazon Linux AMI. keywords: enables more_set_headers, more_clear_headers, nginx-extras
#!/usr/bin/env bash
NGINX_VER=1.12.2
HEADERS_MORE_VER=0.33
PWD=`pwd`
cd /usr/local/src
# get nginx source.
wget http://nginx.org/download/nginx-${NGINX_VER}.tar.gz
wget https://github.com/openresty/headers-more-nginx-module/archive/v${HEADERS_MORE_VER}.tar.gz
tar zxf nginx-${NGINX_VER}.tar.gz
tar zxf v${HEADERS_MORE_VER}.tar.gz
rm -f nginx-${NGINX_VER}.tar.gz v${HEADERS_MORE_VER}.tar.gz
mv headers-more-nginx-module-${HEADERS_MORE_VER} headers-more-nginx-module
# install dev packages.
yum -y install pcre-devel openssl-devel libxml2-devel libxslt-devel perl-ExtUtils-Embed GeoIP-devel gperftools-devel
# build nginx
cd nginx-${NGINX_VER}
./configure --prefix=/usr/share/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 \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-ipv6 \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_geoip_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_gunzip_module \
--with-http_gzip_static_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_ssl_module \
--with-pcre \
--with-google_perftools_module \
--with-debug \
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \
--with-ld-opt=' -Wl,-E' \
--add-module=/usr/local/src/headers-more-nginx-module
make && sudo make install
# install build essentials
sudo yum install gcc-c++ -y
# install nginx with module
chmod +x install_nginx
sudo ./install_nginx.sh
# create nginx.service
sudo vim /lib/systemd/system/nginx.service
# set up nginx service
sudo systemctl enable nginx
sudo systemctl start nginx
# restart nginx
nginx -V
sudo service nginx restart
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment