Cloud Native 10 min read

How to Build a Production‑Ready Nacos Cluster with MySQL and Nginx

This tutorial walks through setting up a Nacos cluster for production, covering MySQL data source initialization, cluster configuration files, local multi‑instance testing, deployment on separate nodes, Nginx reverse‑proxy setup, and common troubleshooting steps.

Programmer DD
Programmer DD
Programmer DD
How to Build a Production‑Ready Nacos Cluster with MySQL and Nginx

This article continues the "Spring Cloud Alibaba Basics" series and explains how to set up a Nacos cluster for production, including MySQL data source configuration, cluster file preparation, local multi‑instance testing, production deployment, and Nginx reverse‑proxy configuration.

Cluster Setup

According to the official documentation, the Nacos cluster architecture is as shown below (the centralized MySQL storage is omitted).

MySQL Data Source Configuration

Before configuring the cluster, initialize the MySQL database using the nacos-mysql.sql file located in the conf directory of the Nacos package.

Then modify conf/application.properties to add MySQL connection details (URL, username, password). Example configuration:

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=
For more details, see the previous article "Nacos Data Persistence".

Cluster Configuration

In the Nacos conf directory there is a cluster.conf.example file. Remove the .example suffix (or create a new cluster.conf) and list the addresses of the Nacos instances to be deployed.

Example for three local instances:

127.0.0.1:8841
127.0.0.1:8842
127.0.0.1:8843
Note: This example is for local testing only; a real production environment should deploy each node on a separate machine to achieve high availability.

Start Instances

For local testing, copy the startup.sh script three times, rename them (e.g., startup-8841.sh, startup-8842.sh, startup-8843.sh) and modify the port parameter -Dserver.port in each script.

Run the scripts:

sh startup-8841.sh
sh startup-8842.sh
sh startup-8843.sh

Production Environment

In a real production deployment, place each Nacos instance on a different node and use the default startup.sh script (adjust JVM parameters only if needed). Execute the script in the bin directory of each node.

Proxy Configuration

After the Nacos cluster is up, configure an Nginx reverse proxy to provide a unified entry point for Spring Cloud applications. Add the following to the http block (image shows the configuration):

Access Nacos via http://localhost:8080/nacos/, which will be load‑balanced across the three instances.

Common issue: using an underscore in the upstream name (e.g., nacos_server ) causes Tomcat to reject the domain. Rename the upstream to nacosserver (remove the underscore).

With the cluster and proxy configured, you can verify the setup by accessing the Nacos address from a Spring Cloud application or by intentionally stopping one instance to test high‑availability behavior.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

service discoverymysqlNGINXSpring CloudCluster Setup
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.