DEV Community

Cheryl M
Cheryl M

Posted on • Originally published at cherylm.hashnode.dev on

Setup VPS - Debian, Nginx, with subdomains

Initial Server Setup

  1. (if it's a reinstall) remove server from known_hosts in .ssh folder
  2. Create a new user and Grant access

  3. Update package repositories

  4. (if sudo is not installed) Install sudo, and add the new user to the sudo group. newUser is then put into the sudo group which members are allowed to use the sudo command in Debian

apt install sudo -y
usermod -aG sudo newUser

Enter fullscreen mode Exit fullscreen mode
  1. Setup firewall (ufw)

  2. (Optional) Top 8 Things to do after Installing Debian 10 (Buster)

(Optional) Setup SSH

  1. Generate the key pair on the client (your computer) In windows powershell

  2. Copy the public key (the generated file with .pub extension) to the server

  3. If everything is setup correctly, we should be able to SSH into the server using the follow command. Enter the pass phrase set up earlier

  4. (optional) To connect to the server without having to specify the identity file every time, edit /.ssh/config , add the following entry for the VPS. Using the same username, VPS IP and filename used above. "Host" can be anything descriptive

Host 123.45.6.7 (newUser)
  HostName 123.45.6.7
  User newUser
  IdentityFile ~/.ssh/<filename>

Enter fullscreen mode Exit fullscreen mode

Now we can simply use the following command to connect to the server

ssh newUser@123.45.6.7

Enter fullscreen mode Exit fullscreen mode

Setup the Web Server (Nginx)

  1. Installation
  2. Setup multiple domains

Remember to Reload Nginx

sudo systemctl reload nginx

Enter fullscreen mode Exit fullscreen mode

(Optional) Setup SSL

This is optional unless your TLD requires it, such as .dev

Let's Encrypt provides SSL certificate which lasts 3 months and can be set to automatically renewed using the certbot package.

  1. How to Set Up SSH Keys on Debian 10

Add Subdomains

  1. Create a new directory like /var/www/subdomain.mydomain.dev/html
  2. Make a new file, subdomain.mydomain.dev in /etc/nginx/sites-available, with the following content

  3. Create symbolic link in sites-enabled

  4. Add SSL Certificates with certbot We have to redo all the old and new domains and subdomains.

  5. Restart nginx

Top comments (0)