apt update
apt list --upgradablecurl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -and
sudo apt install nodejsnmap SERVER_IPAdvanced info for the connection info of all the ports
nmap -sV SERVER_IPsudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT-A append rule-p protocol (tcp, icmp)--dport destination port-j jump (DROP, REJECT, ACCEPT, LOG)For example:
iptables -A OUTPUT -p tcp --dport 80 -j REJECTiptables -A INPUT -s 192.0.0.1 -p icmp --dport 892 -j ACCEPTsudo ufw allow ssh
sudo ufw enableAnd block all outgoing HTTP connections
ufw reject out httpsudo apt install unattended-upgradesCheck the config is right
cat /etc/apt/apt.conf.d/20auto-upgradesIt should be
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";Only update security packages because the software package may change a lot and break something
sudo vi /etc/apt/apt.conf.d/50unattended-upgradesComment the "${distro_id}:${distro_codename}"; line and the file would be:
Unattended-Upgrade::Allowed-Origins {
// "${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
// Extended Security Maintenance; doesn't necessarily exist for
// every release and this system may not have it installed, but if
// available, the policy for updates is such that unattended-upgrades
// should also install from here by default.
"${distro_id}ESM:${distro_codename}";
// "${distro_id}:${distro_codename}-updates";
// "${distro_id}:${distro_codename}-proposed";
// "${distro_id}:${distro_codename}-backports";
};
// List of packages to not update (regexp are supported)
Unattended-Upgrade::Package-Blacklist {
// "vim";
// "libc6";
// "libc6-dev";
// "libc6-i686";
};sudo apt install fail2bansudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.localsudo vi /etc/fail2ban/jail.localIf you misconfigure fail2ban, you can lock yourself out of your server! 4. Check the ban history
sudo tail -f /var/log/fail2ban.logfind /directory -name filename.txt-name can be replaced with type, empty, executable and writablefind /etc -type f -emptyfind / -type d -name loggrep -i ‘jem’ /var/wwwzgrep FILEps aux | grep node|
read from stdout
>
write stdout to file
>>
append stdout to file
<
read from stdin
2>
read from stderrFor example: Read from bar to foo and write in baz
foo < bar > baz#Shell
echo $0chmod 777 filename
chmod -R 777 dirchmod 775 filename
chmod -R 775 dirchmod 774 filename
chmod -R 774 dirchmod 755 filename
chmod -R 755 dirchmod 700 filename
chmod -R 700 dirchmod 666 filename
chmod -R 666 dirchmod 664 filename
chmod -R 664 dirchmod 644 filename
chmod -R 644 dirsudo add-apt-repository ppa:certbot/certbotsudo apt updatesudo apt install python-certbot-nginxsudo certbot --nginxsudo certbot renew --dry-runsudo crontab -eIn this file add
00 12 * * 1 certbot renewThat means renew certificate every week at 12PN on Monday
Open the nginx config file
sudo vi /etc/nginx/nginx.confAdd
gzip on;Refer this for further options
http://nginx.org/en/docs/http/ngx_http_gzip_module.htmlNginx will provide Etag originally.
That means when the file doesn’t change, the server will only send back a Etag.
And the client request status will be 304 - Not modified.
But it bring a request from the client browser eventually. Here we comes the expires headers!
Open site file
sudo vi /etc/nginx/sites-available/defaultAdd settings for expiring static folder’s assets in 30 days
location /static/ {
expires 30d;
proxy_pass http://127.0.0.1:3001/static/;
}Relod Nginx service and verify the result.
The static assets will be loaded from disk cache(or memory cache) and the request status is 200.
The cache-control and expires will match 30 days.
Open site file
sudo vi /etc/nginx/sites-available/defaultAdd settings for cache path etc..
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=slowfile_cache:10m inactive=60m use_temp_path=off;
proxy_cache_key "$request_uri";Add cache folder
location /slowfile {
proxy_cache_valid 1m;
proxy_ignore_headers Cache-Control;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_cache slowfile_cache;
proxy_pass http://127.0.0.1:3001/slowfile;
}Verify it in the browser and see the response header’s X-Proxy-Cache will from MISS to HIT
Open site file
sudo vi /etc/nginx/sites-available/defaultAdd websocket to notify the upgrade in the location / {} section
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:3001;
}Open site file
sudo vi /etc/nginx/sites-available/defaultModify the certbot listen line from listen 443 ssl; to below
listen 443 http2 ssl; managed by certbotOpen site file
sudo vi /etc/nginx/sites-available/defaultAdd a permanent redirect(Will be cache by the search engine)
location /help {
return 301 https://developer.mozilaa.org/en-US/;
}