Skip to content

Instantly share code, notes, and snippets.

@saggiyogesh
Forked from dzlab/build.sh
Created July 24, 2020 19:47
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 saggiyogesh/340228cc362e587d850d3e514f7878ab to your computer and use it in GitHub Desktop.
Save saggiyogesh/340228cc362e587d850d3e514f7878ab to your computer and use it in GitHub Desktop.
Configure NGINX to log HTTP POST request's body
#!/bin/bash
echo "Building NGINX along with Echo module"
# install prerequisites
yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
# download the Echo module
curl -L -O 'https://github.com/openresty/echo-nginx-module/archive/v0.58.tar.gz'
tar -xzvf v0.58.tar.gz && rm v0.58.tar.gz
mv echo-nginx-module-0.58 /tmp/echo-nginx-module
# download NGINX source code
curl -O 'http://nginx.org/download/nginx-1.9.7.tar.gz'
tar -xzvf nginx-1.9.7.tar.gz && rm nginx-1.9.7.tar.gz
cd nginx-1.9.7/
# create user NGINX
groupadd nginx
useradd -G nginx nginx
# install NGINX from source with the Echo module
./configure \
--user=nginx \
--group=nginx \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-file-aio \
--with-http_realip_module \
--add-module=/tmp/echo-nginx-module
make -j2
make install
# cleanup
cd ..
rm -rf nginx-1.9.7/
rm -rf /tmp/echo-nginx-module
#!/bin/bash
echo "Configuring machine to run nginx and support high traffic"
# increase open files limit
echo "fs.file-max = 1073741824" >> /etc/sysctl.conf
echo "nginx soft nofile 40960" >> /etc/security/limits.conf
echo "nginx hard nofile 81920" >> /etc/security/limits.conf
# reload system config
sysctl -p
# edit the index.html file
rm /usr/share/nginx/html/index.html
echo "0" >> /usr/share/nginx/html/index.html
# edit error files (do not fail if files doesn't exist)
rm /usr/share/nginx/html/404.html || true
echo "404" >> /usr/share/nginx/html/404.html
rm /usr/share/nginx/html/50x.html || true
echo "50x" >> /usr/share/nginx/html/50x.html
rm /usr/share/nginx/html/poweredby.png || true
rm /usr/share/nginx/html/nginx-logo.png || true
user nginx;
worker_processes 2;
pid /run/nginx.pid;
events {
worker_connections 8192;
}
http {
server_tokens off;
include mime.types;
default_type application/octet-stream;
log_format custom '$request_body';
sendfile on;
keepalive_timeout 65;
gzip on;
map $request_body $loggable {
'' 0;
'-' 0;
default 1;
}
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/access.log custom if=$loggable;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
root html;
index index.html index.htm;
}
location /events {
# read request body
echo_read_request_body;
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
error_page 405 =200 $uri;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
worker_rlimit_nofile 65536;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment