In this article, we will guide you through setting up a Linux server for web development. We will cover the installation of essential tools and software, including Node.js, MongoDB, Redis, and Nginx, as well as configuring Nginx as a reverse proxy and securing your site with SSL using Certbot. Let’s get started!
First, we need to ensure curl is installed on your system. curl is a command-line tool for transferring data with URLs.
sudo apt install curl
2. Install Node Version Manager (NVM) and Node.js
Node Version Manager (NVM) allows you to manage multiple versions of Node.js. Install NVM using the following commands:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
nvm install node
3. Install MongoDB
Next, we will install MongoDB, a popular NoSQL database. We will start by adding the MongoDB public key to our system:
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
Add the MongoDB repository to the sources list:
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Update the package list and install MongoDB:
sudo apt-get update
sudo apt-get install -y mongodb-org
Start and enable the MongoDB service:
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
sudo nano /etc/mongod.conf
sudo systemctl restart mongod
4. Install Redis
Redis is an in-memory data structure store used as a database, cache, and message broker. Install Redis using snap:
sudo snap install redis
5. Install Nginx
Nginx is a high-performance web server and reverse proxy. Install Nginx with the following command:
sudo apt install nginx
6. Configure Nginx
Create a new Nginx server block configuration file:
sudo nano /etc/nginx/sites-available/example.xyz
Add the following configuration, replacing example.xyz with your domain name or server IP:
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/m;
server {
server_name example.online; # Replace with your domain or server IP
location /{
proxy_pass http://localhost:6490/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Create a symbolic link to enable the configuration:
ln -s /etc/nginx/sites-available/example.xyz /etc/nginx/sites-enabled/
Test the Nginx configuration and reload the service:
sudo nginx -t
sudo systemctl reload nginx
7. Secure Your Site with SSL using Certbot
Install Certbot, a tool to obtain and renew Let’s Encrypt SSL certificates:
sudo apt install certbot python3-certbot-nginx
Run Certbot to obtain and install the SSL certificate:
sudo certbot --nginx -d example.xyz
Follow the prompts to complete the installation and enable HTTPS on your site.
Congratulations! You have successfully set up a Linux server with Node.js, MongoDB, Redis, and Nginx. Additionally, you configured Nginx as a reverse proxy and secured your site with an SSL certificate using Certbot. Your server is now ready to host your web applications. Happy coding!