UpCloud
Effortless global cloud infrastructure for SMBs
Introducing
If you’re interested in what we have to offer, contact sales or fill out a contact form.
Our support live chat is available for our customers 24/7. You can also email our support team.
Send us an email to give feedback or to say hello.
Start a new journey
Why Partner with UpCloud?
I’ve been passionate about the hosting industry since 2001. Before founding UpCloud, my first company grew to become one of Finland’s largest shared web hosting providers, serving over 30,000 customers. Along the way, I faced the same challenges many of you know well—24/7 on-call responsibilities, solving technical issues, and managing customer inquiries.
At UpCloud, we’ve designed a platform that solves these challenges, offering reliability, scalability, and unparalleled support. We understand the pressures you face because we’ve been there too. Partner with us, and let’s help you focus on growing your business while we handle the rest.
Sincerely, Joel Pihlajamaa CTO, Founder
Login
Sign up
Updated on 10.7.2025
Next.js is one of the most popular frameworks for building modern web applications, offering the flexibility of server-side rendering (SSR), static site generation (SSG), and an optimized developer experience on top of React. Whether you’re building a personal project, an internal tool, or a high-traffic production application, Next.js makes it easier to create fast, scalable, and SEO-friendly web experiences.
But building the app is only half the journey. Deploying your Next.js application to a cloud server is where the real magic happens. By hosting your project in the cloud, you unlock a range of benefits:
In this guide, we’ll walk you through deploying a Next.js application on a cloud server step by step. Whether you’re new to deployment or looking to refine your cloud setup, you’ll learn how to:
By the end of this guide, you’ll have a fully functional Next.js application running on a cloud environment, ready to serve users with speed and reliability. So, let’s dive in!
Before we jump into deploying your Next.js application to the cloud, ensure you have the following set up:
First, we need to create a new server on UpCloud and connect your SSH keys to it. UpCloud’s intuitive interface makes it easy to do this, even if you’re new to cloud servers. See the documentation for a detailed workflow on how to create and deploy a new server.
Next, connect to the UpCloud server via SSH using your server’s IP address and the SSH key you set up during server creation. UpCloud supports only SSH key authentication, ensuring secure access. If you’re using a terminal on your local machine (Mac, Linux, or WSL on Windows), the command will look something like this:
ssh username@your_server_ip_address
(Don’t forget to replace username and your_server_ip_address with your actual credentials!)
username
your_server_ip_address
Once connected, let’s install Node.js and npm (npm is usually bundled with Node.js). We’ll use the Node Version Manager (nvm) for easier Node.js version management. This is highly recommended, as it allows you to easily switch between Node.js versions if needed.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash source ~/.bashrc
Then, install the latest LTS version of Node.js using the command: nvm install --lts
nvm install --lts
node-v
npm-v
npm install -g yarn yarn -v # check version
Now, it’s time to get your Next.js project onto the server. There are a couple of ways to do this:
SSH (for smaller projects): You can use scp (secure copy) to transfer your project. From your local machine:
cd /var/www
mkdir my-nextjs-projects
scp -r your_project_directory username@your_server_ip_address:/path/to/destination/
Clone your Next.js project from the Git repository: Since our project is in a Git repository, let’s clone the repository on the server.
cd my-nextjs-projects
git clone https://github.com/Anita-ihuman/nextjs-blog.git
Next, we will install all the necessary packages for our project on the server. Simply run the following command to read the package.json file and provide all necessary dependencies our app needs.cd nextjs-blog
package.json
cd nextjs-blog
npm install # Or yarn install if you're using yarn
With the environment set up and our project in place, we’re ready to build our Next.js application for production. This process optimizes our code for performance and prepares it for deployment.
Build the Next.js app using the following command: npm run build # Or yarn build
npm run build # Or yarn build
This command will compile your Next.js application, optimize images, create static assets, and generate everything needed to run your app efficiently. The output will be placed in a .next directory within your project folder.
.next
Optimization Features:
Next.js comes packed with optimizations that are automatically applied during the build process. These optimizations are crucial for ensuring the Next.js application performs well in a production environment. The npm run build command takes care of the following behind the scenes so we can focus on building the application’s features:
npm run build
<Image>
build
After a successful build, we are ready to deploy!
Now that we’ve built our optimized Next.js application, it’s time to set up a production server to launch our app to the world. Think of this as building the control room for our Next.js deployment. We’ll explore different server options and walk through setting up a reverse proxy with Nginx, a popular choice for Next.js hosting.
You have several options when it comes to serving your Next.js app:
next start
So, for this tutorial, we’ll focus on setting up Nginx as a reverse proxy, as it’s the most common and robust approach for Next.js hosting.
We need Nginx to act as a front-facing server, handling incoming requests and forwarding them to our Next.js application. This setup offers several advantages, including improved performance, security, and the ability to serve static files efficiently.
sudo apt-get update # Update package lists (if on Debian/Ubuntu)
sudo apt-get update # Update package lists
sudo apt-get install nginx
sudo nano /etc/nginx/sites-available/next-js-app # Replace with your project name!
Paste the following configuration into the file, adjusting the paths and ports with the Server name and IP (I am using my domain main in this instance). If you do not have a domain name, you can use the server IP we got from UpCloud accordingly.
server { listen 80; server_name your_domain_or_ip; # Replace with your domain or server IP location / { proxy_pass http://localhost:3000; # Replace with your port number to Forward requests to Next.js server 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; } location /_next/static/ { alias /var/www/my-nextjs-projects/nextjs-blog/.next/static/; # Change to your file path access_log off; expires 1y; add_header Cache-Control "public, max-age=31536000, immutable"; } }
In my case, I have a domain name I have previously created on name.com. I updated the DNS details with the server IP from UpCloud. Then, I updated my Nginx config file accordingly.
sudo ln -s /etc/nginx/sites-available/nextjs-blog /etc/nginx/sites-enabled/ sudo systemctl restart nginx
.env
Next.js supports environment variables, which are essential for storing sensitive data like API keys, database credentials, and other configuration values. Create a .env.local file in the root of the project and add the following variables:
.env.local
MONGO_URI: JWT_SECRET: CLOUDINARY_URL:
Next.js will automatically load these environment variables during the build process.
With your server configured, it’s time to deploy your Next.js application and make it accessible publicly. We’ll explore two primary deployment strategies: using a process manager like PM2 and leveraging the streamlined one-click deployment options offered by UpCloud
Deploying with PM2 (Process Manager):
PM2 is a production process manager for Node.js applications that comes with a built-in load balancer. Think of it as the conductor of your Next.js orchestra, ensuring the app runs smoothly and continuously. It handles restarts in case of errors, monitors performance, and simplifies deployment management.
npm install -g pm2
Start your application using PM2 with the following command:
pm2 start npm --name "nextjs-blog" -- start #Ensure your package.json contains "start": "next start" curl -I http://127.0.0.1:3000
node server.js
pm2 start "node server.js" --name "nextjs-blog"
pm2 startup # Generates a startup script pm2 save # Saves the current process list so PM2 can restore it on boot pm2 delete <process_name_or_id> # Removes a process (or application) that is being managed by PM2
At this point, our Next.js deployment should be publicly accessible and available via URL using the domain name specified in the Nginx configuration or the server IP(www.anitaihuman.dev)
With our Next.js application live on the UpCloud server, the critical next step is thorough testing to evaluate its performance and reliability and ensure it runs optimally in production. UpCloud provides monitoring and troubleshooting services that can help with this process.
You can use UpCloud’s built-in monitoring tools to track CPU, memory, disk I/O, and network usage and identify potential bottlenecks. UpCloud’s Layer 3 (L3) firewall provides a powerful way to control server traffic by filtering connections based on IP address and port, adding an extra layer of protection before traffic reaches your application. You can also review logs in your UpCloud server by connecting with monitoring and logging tools like Prometheus + Grafana to diagnose issues.
/etc/nginx/sites-available/your_project_name
http://localhost:3000
pm2 list
sudo fallocate -l 2G /swapfile or sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
NODE_OPTIONS="--max_old_space_size=512" npm run build
sudo chown -R www-data:www-data
/var/log/nginx/error.log
Deploying a Next.js application efficiently requires a combination of performance optimizations, SEO considerations, security measures, and balance cost-effectiveness. The best way to deploy a Next.js app and ensure it runs smoothly in production while maintaining speed, security, and search engine visibility is to:
In this guide, we’ve walked through the essential steps of deploying your Next.js application on an UpCloud server. We began by setting up the development environment, installing Node.js and npm/yarn, and uploading your project. We then covered building your Next.js app, highlighting the built-in optimization features. Next, we delved into configuring a production-ready server, discussing various options and focusing on setting up Nginx as a reverse proxy. We also explored how to manage environment variables securely. We then moved on to deploying your application using PM2 and using the domain name, we also made our app publicly accessible over the web.
By following these steps, you can confidently deploy and manage your Next.js applications on UpCloud, taking advantage of its powerful features and flexible infrastructure.
Ready to launch your Next.js project on UpCloud? Try UpCloud today!
What is the best way to deploy a Next.js app?
There are several ways to deploy a Next.js app, depending on your needs:
For most production use cases, deploying on a cloud server (or a managed platform like Vercel) offers the best balance of flexibility and reliability.
How do I install Next.js on a cloud server?
Installing Next.js on a cloud server like UpCloud is straightforward. You just need to:
What is the difference between building and deploying a Next.js app?
Can I host Next.js apps for free?
Yes, platforms like Vercel and Netlify offer free hosting for Next.js apps, which is great for small projects and prototypes. However, free plans often have limitations like cold starts, bandwidth restrictions, and lack of full server control.
For serious production apps, a cloud provider like UpCloud gives you more flexibility, better performance, and full control over your setup.
What are common deployment errors in Next.js?
Some common issues and fixes include:
next build
If something breaks, check your logs—Next.js usually gives useful error messages to help debug issues.
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Δ
See all tutorials