# Obligatory
sudo apt-get update
sudo apt-get install -y zsh git-core
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Change the shell to zsh
sudo chsh -s $(which zsh) username
sudo nano /etc/ssh/sshd_config
# Disable Password based auth
PasswordAuthentication no
# Change port number
Port 50683
Restart SSH Daemon
sudo service ssh restart
Secure MySQL installation
mysql_secure_installation
# Allow SSH to run on port 50683
sudo ufw allow 50683/tcp
# Allow HTTP traffic
sudo ufw allow 80/tcp
# Allow SSL Traffic
sudo ufw allow 443/tcp
After you've finished adding the exceptions, you can review your selections by typing:
sudo ufw show added
If everything looks good, you can enable the firewall by typing:
sudo ufw enable
sudo dpkg-reconfigure tzdata
Configure NTP. This will allow your computer to stay in sync with other servers, leading to more predictability in operations that rely on having the correct time.
sudo apt-get install ntp
Open Nginx configuration
sudo nano /etc/nginx/nginx.conf
Tweak these settings:
# Optimized for DigitalOcean 512MB, 1CPU instance.
# Do your own Math for other larger setups.
worker_processes 1;
worker_connections 1024;
keepalive_timeout 10;
# Refer nginx.conf attached to this gist.
Create a custom configuration file
sudo nano /etc/nginx/conf.d/settings.conf
# Copy paste these tweaks from settings.conf attached to this gist.
Restart Nginx
sudo service nginx restart
# Temporarily disable firewall to allow letsencrypt to verify domain name.
sudo ufw disable
# Clone letsencrypt to your hone directory
cd ~/ && git clone https://github.com/letsencrypt/letsencrypt
# Stop Nginx
sudo service nginx stop
# Obtain certificate from letsencrypt. Remember that your email mentioned on your whois record should match the email address and domain your provide.
cd ~/letsencrypt && ./letsencrypt-auto --agree-dev-preview --server https://acme-v01.api.letsencrypt.org/directory auth
It should now tell you where the certs are stored. For me, it was /etc/letsencrypt/live/example.com
# Enable firewall back on.
sudo ufw enable
# certs should be readable by www-data
sudo chown :www-data /etc/letsencrypt/live/example.com/privkey.pem
sudo chown :www-data /etc/letsencrypt/live/example.com/fullchain.pem
# Finally, remove letsencrypt folder
cd ~/ && sudo rm -r letsencrypt/
Server blocks are nothing but vhosts in the Apache world.
# Won't use the default. It's easier to work in /var/www directory
sudo mkdir -p /var/www/example.com/html
# Transfer ownership to regular user.
sudo chown -R $USER:$USER /var/www/example.com/html
# The permissions should be correct, but just to be safe.
sudo chmod -R 755 /var/www
Create an index.html to test server blocks
nano /var/www/example.com/html/index.html
Copy paste a sample html, this is just to test our server block.
<html>
<head>
<title>Welcome to Example.com!</title>
</head>
<body>
<h1>Success! The example.com server block is working!</h1>
</body>
</html>
Replace the contents of the default server block, with the contents of default attached to this gist.
sudo rm /etc/nginx/sites-available/default
sudo nano /etc/nginx/sites-available/default
# Now copy the contents of default attached to this gist
Let's make a custom log folder.
sudo mkdir -p /etc/nginx/logs/static
sudo touch /etc/nginx/logs/static.log
Create a brand new server block
sudo nano /etc/nginx/sites-available/example.com
# Just copy serverblock attached to this gist.
# Don't forget to replace example.com to your own domain.
Enable the server block
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
# Install pip
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv
# Install ngxtop
sudo pip install ngxtop
# For access logs
# sudo ngxtop -l /var/log/nginx/access.log
# For error logs
# sudo ngxtop -l /var/log/nginx/error.log
# For more details: https://github.com/lebinh/ngxtop