My Blog
Thoughts, insights, and stories on software engineering, design, and life.
How to host a Next.js app in Production on an Ubuntu VPS
# How to Host a Next.js App in Production on an Ubuntu VPS
> "Deploying a Next.js application on an Ubuntu Virtual Private Server (VPS) offers unparalleled control, flexibility, and cost-effectiveness compared to managed platforms. By leveraging robust tools like PM2 for process management and Nginx as a reverse proxy, developers can ensure their applications run smoothly, securely, and handle high traffic volumes efficiently."
* **By:** Talha Shahid Khan
* **Updated:** October 10, 2026
In recent years, Next.js has become the go-to framework for building fast, SEO-friendly React applications. While managed platforms like Vercel make deployment incredibly simple, hosting your Next.js app on an Ubuntu Virtual Private Server (VPS) provides more control over your infrastructure, eliminates vendor lock-in, and can significantly reduce costs as your application scales.
If you are ready to take your deployment skills to the next level, this guide will walk you through the essential steps to get your Next.js application running in production on an Ubuntu VPS.
## Prerequisites for Deployment
Before we dive into the setup, you will need a few things:
* An Ubuntu VPS (20.04 or 22.04 LTS) from providers like DigitalOcean, Linode, or AWS.
* A registered domain name pointed to your server's public IP address.
* Root or sudo access to your server.
* Your Next.js project pushed to a Git repository (like GitHub or GitLab).
## Step 1: Prepare Your Server and Install Node.js
First, connect to your server via SSH. It is always a good practice to start by updating your package lists to ensure you have the latest security patches and software updates.
```bash
sudo apt update && sudo apt upgrade -y
```
Next, you need to install Node.js. The easiest way to get the latest LTS version is via NodeSource:
```bash
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
```
Verify the installation by checking the versions:
`node -v` and `npm -v`.
## Step 2: Clone and Build Your Next.js Project
Navigate to the directory where you want to store your application, typically `/var/www/`, and clone your repository.
```bash
cd /var/www
sudo git clone https://github.com/yourusername/your-nextjs-app.git
cd your-nextjs-app
```
Install your project dependencies and create a production build. The build process optimizes your application for the best performance.
```bash
npm install
npm run build
```
## Step 3: Keep Your App Alive with PM2
If you simply run `npm start`, your app will stop the moment you close your SSH session. To keep your Next.js app running in the background and automatically restart it if it crashes, we use a process manager called **PM2**.
Install PM2 globally:
```bash
sudo npm install -g pm2
```
Start your Next.js application using PM2:
```bash
pm2 start npm --name "nextjs-app" -- start
```
To ensure PM2 automatically starts your app when the server reboots, run:
```bash
pm2 startup
pm2 save
```
## Step 4: Configure Nginx as a Reverse Proxy
By default, Next.js runs on port `3000`. We need to use Nginx to listen on port 80 (HTTP) and route that traffic to your Next.js app.
Install Nginx:
```bash
sudo apt install nginx -y
```
Create a new Nginx configuration file for your site:
```bash
sudo nano /etc/nginx/sites-available/yourdomain.com
```
Paste the following configuration, making sure to replace `yourdomain.com` with your actual domain:
```nginx
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
```
Enable the configuration by creating a symlink to the `sites-enabled` directory, test Nginx, and restart the service:
```bash
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```
## Step 5: Secure Your App with SSL
Security is non-negotiable for modern web applications. Let's Encrypt provides free SSL certificates that you can easily install using Certbot.
```bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
```
Follow the prompts to configure your certificate. Certbot will automatically update your Nginx configuration to route traffic to HTTPS (port 443) and set up auto-renewal.
## Conclusion
Congratulations! Your Next.js application is now successfully running in a robust production environment. By utilizing an Ubuntu VPS, PM2, Nginx, and Let's Encrypt, you have built a scalable and secure hosting architecture.
As your traffic grows, this setup gives you the flexibility to easily upgrade your server resources, tweak your Nginx caching strategies, and maintain full ownership over your deployment pipeline. Happy coding!
Read Article
How Algorithmic Trading Systems Work?
# How Algorithmic Trading Systems Work
> "In Bangladesh, the popularity of online trading has helped transform the financial landscape. This has led to over 20% of all trading is now done via mobile through trading apps. In line with this, another development many traders have highlighted is the use of algorithmic trading systems to take advantage of ever-changing market opportunities. To date, algorithmic trading systems are used in up to 60% of all trading volume."
- **By:** Talha Shahid Khan
In India, the popularity of online trading has helped transform the financial landscape. This has led to over 20% of all trading now being done via mobile through trading apps. In line with this, another development many traders have highlighted is the use of algorithmic trading systems to take advantage of ever-changing market opportunities. To date, algorithmic trading systems are used in up to 60% of all trading volume.
## What are algorithmic trading systems?
Algorithmic trading systems, or **algo-trading** for short, refer to the use of computer programs to automatically execute trades in financial markets. These trades are based on predetermined rules set by the trader.
With a single program, traders are able to process large amounts of data and make trades at high speeds, which helps them take advantage of online trading opportunities. These programs are also able to react in a more timely manner and reduce any risks associated with sudden volatile dips before significant losses are incurred.
## How do algorithmic trading systems work?
Essentially, algo-trading uses mathematical models and statistical analysis to execute trades in financial markets. A computer program is responsible for an automated trading approach that is able to process market data and make trades without constant human supervision. Apart from profit opportunities for the trader, the algorithm also makes trading more systematic by ruling out the impact of human errors on trading activities.
To ensure success, it is critical to use the right programming language. Different programming languages have their own strengths and weaknesses, and the wrong choice can slow down the analytical process and lower profitability. Furthermore, the varying data structures within different financial markets may require the use of a specific programming language for optimal performance.
Currently, the common programming languages used in algo-trading include **Python**, **Java**, **C++**, and **R**. As explained in our program cheatsheet, Python is popular for its versatility. In algo-trading, this versatile nature means that traders can experiment with different strategies first without needing to commit to more complex codes. Additionally, it has a more understandable syntax that ensures accessibility across most trader levels. However, R is a popular choice for traders who are focused on maximizing statistical analysis and data visualization. Regardless of the programming language used, it is important to use the one that will simplify development and reduce complexity for trading.
## Application of algorithmic trading systems
Given the capabilities of algo-trading, applying its use is fairly easy. There are several exchanges and brokers in India that offer algo-trading platforms and services. At present, this includes the **National Stock Exchange of India (NSE)** and the **Bombay Stock Exchange (BSE)**.
In terms of specific assets, several can benefit from algo-trading:
- **Indices:** Trading decisions can be made with more nuance given algo-trading's real-time reactions. Since the indices market allows for speculation on the performance of an index rather than investing in it, traders can program their algorithm to capitalize on the movements of prices without getting distracted by the actual stock's standing. This is important for traders, as an algorithm can rapidly analyze data and prices across the thousands of global indices across large and small companies.
- **Cryptocurrencies:** The massive interest in cryptocurrencies within India is also an area where algo-trading can thrive. Creating the right algorithm with crypto in mind ensures that trades are executed consistently within a predefined strategy to prevent losses with volatile digital assets. This is also timely given the planned digital currency from the BRICS bloc, as India can take advantage of algo-trading to keep up with changes dependent on all of the concerned countries.
As it stands, the application of algo-trading has created a digitally driven community where the future remains bright for Indian traders. After all, India has a robust population of software developers, where 5.8 million individuals work to provide top-notch programs. As such, traders are looking forward to even more innovations that can enhance the investment industry.
Read Article
How to find the Python Installation Path on Windows?
# How to Find the Python Installation Path on Windows
> Discover how to locate the Python installation path on your Windows system using two effective methods: the traditional Command Prompt and the modern Terminal. Whether you're troubleshooting or setting up environment variables, this guide provides clear, step-by-step instructions with visuals to help you find the information you need. Explore now!
- **By:** Talha Shahid Khan
---
Locating the installation path of Python on your Windows system is essential for various tasks such as setting up environment variables or troubleshooting issues. In this guide, I will show you two methods to help you find the Python installation path: first using the traditional **Command Prompt (CMD)**, and second using the newer **Terminal (PowerShell)**.
---
## Method 1: Using Command Prompt (CMD)
This classic method involves utilizing Windows' Command Prompt to find where Python is installed.
### Step 1: Open Command Prompt
1. Press Win + R to open the **Run** dialog.
2. Type `cmd` and press Enter.
### Step 2: Use the `where` Command
In the Command Prompt window, type the following command:
```cmd
where python
```
Press Enter, and the system will display the paths where Python is installed.
---
## Method 2: Using Terminal
The Windows Terminal is a powerful scripting environment and newer command-line shell, offering a modern approach to interacting with your system. If you prefer using Terminal, follow the steps below:
### Step 1: Open Terminal
Search for **Terminal** in the Start menu and select it to launch.
### Step 2: Use the `Get-Command` Command
In the Terminal window (PowerShell profile), type the following command:
```powershell
(Get-Command python).Path
```
Press Enter, and Terminal will reveal the path where Python is currently resolved and installed.
---
## Conclusion
Both the **Command Prompt** and **Terminal** methods are quick and effective ways to find the Python installation path on your Windows system. While Command Prompt is familiar and classic, Terminal offers a modern and powerful alternative.
Whether you are troubleshooting an issue, adding Python to your system `PATH`, or configuring IDEs, these two commands give you the precise information you need.
Feel free to drop a comment below if you have any questions or require further assistance.
**Happy coding!**
Read Article