Here's a script I wrote for raising up a basic Nginx server environment.
The script includes an internal script named csb (create Sblock) which is used to create Sblocks in a comfortable way. As I'm new to Linux, I might have had about 2-3 mistakes, especially in that internal script.
#!/bin/bash -x
function nginx {
apt-get update -y && apt-get upgrade -y
apt-get install unattended-upgrades tree zip unzip -y
dpkg-reconfigure --priority=low unattended-upgrades
mkdir /root/backups /root/backups/db /root/backups/dirs
ufw app list # Orient your firewall for Nginx.
cd /usr/src && rm -fv csf.tgz
wget https://download.configserver.com/csf.tgz && tar -xzf csf.tgz
cd csf && sh install.sh
sed -i 's/TESTING = "1"/TESTING = "0"/g' /etc/csf/csf.conf
csf -r && perl /usr/local/csf/bin/csftest.pl
cd /usr/local/src && wget http://www.rfxn.com/downloads/maldetect-current.tar.gz && tar -xzf maldetect-current.tar.gz
cd maldetect-* && bash ./install.sh && cd ~
# systemctl stats/stop/start/restart/reload/disable/enable # disable/enable --- at boot. # nginx -t
apt-get install nginx mysql-server php-fpm php-mysql
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.0/fpm/php.ini
sed -i 's/server_names_hash_bucket_size ..;/server_names_hash_bucket_size ..;/g' /etc/nginx/nginx.conf
restart php7.0-fpm
# http://ip_address
cat <<-'CSB' > /etc/nginx/sites-available/csb
#!/bin/sh
for domain; do
> "/etc/nginx/sites-available/${domain}.conf" cat <<EOF
server {
listen 80;
listen [::]:80;
root /var/www/html/${domain};
index index.php index.html index.htm index.nginx-debian.html;
server_name ${domain} www.${domain};
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
EOF
ln -s /etc/nginx/sites-available/${domain} /etc/nginx/sites-enabled/
done
systemctl restart nginx.service
CSB
chmod +x /etc/nginx/sites-available/csb
cat <<-'BASHRC' > /etc/bash.bashrc
alias csb="bash /etc/nginx/sites-available/csb"
BASHRC
reboot
} nginx
Note: For some reason I can't indent the code under ln, here in Code Review.