#!/bin/bash

nginx_install(){
useradd -M -s /sbin/nologin nginx
mkdir /var/cache/nginx/ngx_cache -p
yum -y install GeoIP GeoIP-devel GeoIP-data gperftools libxml2 libxml2-dev libxslt-devel
cd /root && wget -c http://54.179.201.103:8001/nginx/nginx-1.16.0.tar.gz && tar -xvf /root/nginx-1.16.0.tar.gz
cd /root/nginx-1.16.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/usr/local/nginx/nginx.pid --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_slice_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_ssl_preread_module --with-google_perftools_module --with-pcre --with-http_stub_status_module
make && make install
}

nginx_optimize(){
cd /usr/local/nginx/conf && mkdir vhosts
rm -f /usr/local/nginx/conf/nginx.conf
wget  http://54.179.201.103:8001/nginx/proxy.conf
wget  http://54.179.201.103:8001/nginx/gzip.conf
wget  http://54.179.201.103:8001/nginx/nginx.conf

cd /etc/logrotate.d/
wget http://54.179.201.103:8001/nginx/nginx
logrotate /etc/logrotate.conf

mkdir -p /opt/scripts/ && cd /opt/scripts
wget http://54.179.201.103:8001/nginx/tcp_status.sh && chmod +x /opt/scripts/tcp_status.sh

cd /etc/zabbix/zabbix_agentd.d/
wget http://54.179.201.103:8001/nginx/tcp_status.conf
systemctl restart zabbix-agent.service
systemctl enable zabbix-agent.service
systemctl enable zabbix-agent.service
}


nginx_install
nginx_optimize
