Deploying Next.js Projects with Coolify
This article provides a detailed guide on how to deploy Next.js projects using Coolify to help you quickly launch your project.
Since Coolify has higher VPS performance requirements than Dokploy, if your VPS has lower specifications, please choose Dokploy and refer to the Dokploy Deployment Documentation.
Prerequisites
Before starting the deployment, it's recommended to add the following configuration to next.config.mjs:
const nextConfig = {
output: "standalone", // Add this line
// other code...
}Since Coolify runs on Docker, using standalone mode can significantly reduce the build image size.
What is Coolify
Coolify is an open-source self-hosted PaaS (Platform as a Service) platform that serves as an open-source alternative to services like Vercel, Netlify, Railway, and Zeabur.

Server Preparation and Coolify Installation
Purchasing a Server
Using Coolify requires purchasing your own server. If you're unsure which service provider to choose, consider hostinger. For initial projects, a 4-core 16GB VPS is sufficient, costing only $7.99 per month.

Configuring the Server
After completing payment, follow the on-screen instructions to set up your VPS. Once configured, the dashboard will show that the VPS has started.
Next, you need to configure firewall rules. Hostinger has no default firewall rules, which means all ports are open, posing a security risk. We need to create firewall rules to allow access to ports 22, 80, 443, and 8000.
Port 8000 is used to access the Coolify registration page. Once you complete the custom domain setup for Coolify later, you should close port 8000.


Installing Coolify
You can install it via command line following the official documentation, or install it directly from the Hostinger dashboard.

After installation is complete, open http://your_server_ip:8000 to access the Coolify dashboard.


Configuring Coolify
After registering and logging in, first set up a custom domain for the dashboard:

Then add a DNS record for this custom domain on your DNS platform (using CloudFlare as an example), select A record type, and enter your server IP address.

Once the DNS propagates, you can access the Coolify dashboard using the custom domain.
Remember to remove port 8000 from the firewall. From now on, only use the domain to access.
Finally, connect your Git account as shown below:




Deployment Steps
Coolify provides a Vercel-like visual deployment interface where you can easily select a GitHub repository for automatic deployment.





Configure custom domain and redirect rules:

After creation, you need to set up DNS in Cloudflare:

Add two records:
A record:
your-domain.com -> your server IP
Enable Proxy
A record:
www.your-domain.com -> your server IP
Enable ProxyThen open SSL/TLS settings and select Full or Flexible:

Configure environment variables:


Then click the Deploy button in the top right corner to start automatic deployment.
View build progress:

From now on, every code commit will automatically trigger a deployment.
Advanced Usage
Logging
If you're using Pino for logging in your Next.js project, you can mount the log directory to the host machine using Coolify's features.
- Click "Persistent Storage" in the left menu
- Click "+ Add" to add a new storage mount and fill in the following:
- Source Path (host machine path):
/var/log/nexty-dev - Destination Path (container path):
/app/logs
- Source Path (host machine path):


- Save the configuration and click Redeploy

After the configuration takes effect, log files written to /app/logs in the container will actually be saved to /var/log/nexty-dev on the host machine.
Viewing logs on the VPS:
# View log file list
ls -la /var/log/nexty-dev/
# View logs in real-time
tail -f /var/log/nexty-dev/xxxxxxxx-*.log
# Search for specific content
grep "error" /var/log/nexty-dev/xxxxxxxx-*.logTo view logs locally, you can use the scp command to export the entire folder or specific files:
# Execute on your local machine
scp -r root@ip:/var/log/nexty-dev/ ./nexty-logs/Deploying Redis
The steps for creating Redis are similar to creating a regular project, except you need to select Redis as the Resource.


After creation, you can see the configuration information:

For production environments, if deployed on the same server, you can directly use the internal link.
Other key configuration options:
- Ports Mappings: Maps
host_port:container_port. For example, if you need temporary local debugging, you can set it to6380:6379, allowing local access to Redis via IP and port 6380. - SSL Configuration:
- Traffic connecting to Redis will be encrypted via TLS/SSL.
- Recommended to enable to prevent your data and password from being intercepted during transmission.
- Once enabled, your client connection string typically needs to change from
redis://torediss:// - Download the CA file generated by Coolify on your local machine using:
echo | openssl s_client -connect 72.62.133.215:23771 2>/dev/null | openssl x509 > redis_server.crt
- Proxy - Make it publicly available:
- Unchecked: Only applications within the same Coolify instance can access this Redis
- Checked: Can only be enabled if Public Port is set; once checked, a Public URL will be displayed.
- Public Port: Defines the port number used to access Redis through the server IP. If needed, it's recommended to set a 5-digit uncommon port for better security than 6379.
For temporary local debugging, use Ports Mappings and close the port immediately after use. If you need to maintain internet access, it's recommended to set up SSL, Proxy, and Public Port.
Whether connecting through Ports Mappings or Proxy, you need to open the corresponding port in the VPS firewall.
Enabling AOF for Redis
If you need data persistence for Redis, you can enable AOF by adding these two lines in Custom Redis Configuration:
appendonly yes
appendfsync everysecThen scroll to the top and click Save, then Restart.
To verify if AOF is correctly enabled, open the Terminal at the top and execute the commands:
redis-cli
AUTH YOUR_PASSWORD
CONFIG GET appendonly