!!! Work in progress, use at your own risk. !!!
- nginx
- certbot
- iptables
Add a new user for the purposes of logging in and doing administrative work.
The root user has permissions to change every aspect of your server. This is good for the sake of administration, but regularly logging in and navigating your VPS as root isn’t great for security.
adduser usernameYou will be prompted with:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfullyAdd the new user to the sudo group.
usermod -aG sudo remote-userAfter logging out, and back in as the new user, make sure your sudo access is working. One way of doing this is by listing the /root/ directory, which is only possible with sudo access. You’ll be asked for your user’s password to authenticate.
sudo ls -la /root
[sudo] password for username:$ sudo apt install nginx -y;
$ sudo systemctl enable --now nginx;First two variables to tune are worker_processes and worker_connections.
worker_processess - how many workers should be spawn worker_connections - how many clients can be simultaneously connection
Configure worker connections to be the number of cores available. Run the following to display the cores available:
grep processor /proc/cpuinfo | wc -lCheck the core’s limitations by issuing a ulimit command:
ulimit -nUpdate the config with the new values.
sudo nano /etc/nginx/nginx.conf
worker_processes 1;
worker_connections 1024;Create the website directory in /var/www:
$ sudo mkdir -p /var/www/www.mywebsite.com
$ cd /var/www/www.mywebsite.com
$ nano index.htmlPaste the following into nano editor:
<!DOCTYPE html>
<html>
<head>
<title>Nginx Static Website</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>Next add a server configuration block. Instead of going through site-available folders and then creating symlinks, just write the server block in there conf.d folder. It will work on all platforms and it is simpler to manage:
$ nano /etc/nginx/conf.d/www.mywebsite.com.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/www.mywebsite.com;
index index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}Remove the default configuration and reload nginx:
$ sudo rm /etc/sites-enabled/default
$ sudo systemctl reload nginx