How to Deploy a Node.js Community Site on Tencent Cloud: Step‑by‑Step Guide
This guide walks you through purchasing a Tencent Cloud instance, installing and configuring Nginx, Node.js, MongoDB, and setting up deployment scripts, covering SSH access, compiling the latest Nginx with HTTP/2 support, and automating service startup for a robust community website.
Recently we acquired a Tencent Cloud server to build a community site. The architecture includes MongoDB as the database service, a Node.js + Express backend, and Nginx as the entry point.
Database service: MongoDB
Backend: Node.js + Express
Access: Nginx
The key steps from purchase to deployment are:
Server purchase
Nginx compilation, installation, and configuration
Node.js installation
MongoDB installation
Server deployment
Server Purchase
Find the purchase entry on the Tencent Cloud homepage. Choose the configuration you need; annual packages offer a discount (pay for 10 months only). After purchase, the machine’s IP is available within minutes.
Login to the Machine
<code>ssh [email protected]</code>Log in first with username and password, then set up password‑less SSH.
Nginx Installation
Install Nginx using
apt-get:
<code>sudo apt-get install nginx</code>This is the simplest method, but it may not provide the latest version. To support HTTP/2 we need at least Nginx 1.9.5, so we compile the latest version from source.
<code>wget https://nginx.org/download/nginx-1.10.1.tar.gz
tar -xvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
# Install build dependencies
sudo apt-get install make libssl-dev zlib1g-dev openssl pcre3-dev
# Configure and compile
./configure --with-http_ssl_module --with-http_v2_module
make
sudo make install
# Create a symlink for the nginx command
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
# Verify installation
nginx -V
# Set up automatic start
sudo wget https://raw.githubusercontent.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d -f nginx defaults
# Start Nginx
sudo /etc/init.d/nginx start</code>MongoDB Installation
MongoDB can be installed directly with
apt-get:
<code>sudo apt-get install mongodb
# Enable auto‑start on boot
sudo update-rc.d -f mongodb defaults
# Start MongoDB
sudo /etc/init.d/mongodb start</code>Node.js Installation
<code># Download pre‑compiled Node.js
wget https://nodejs.org/dist/v4.6.0/node-v4.6.0-linux-x64.tar.xz
tar -xvf node-v4.6.0-linux-x64.tar.xz
cd node-v4.6.0-linux-x64
# Copy binaries to /usr/local
sudo cp -r bin include lib share /usr/local/
# Verify installation
node -v</code>Server Deployment
Preparation steps:
<code># Create deployment directory
sudo mkdir -p /data/www/ivweb.io
# Create a dedicated user and group
sudo groupadd www
sudo useradd www -g www -d /data/www
# Set permissions for /data
sudo chown www:www /data
# Install forever to keep the Node app running
sudo npm install -g forever</code>Synchronize files to the server using rsync (Windows users need to install rsync first):
<code>rsync -rtzvlC --exclude node_modules --exclude ".git" \
./ "[email protected]:/data/www/ivweb.io"</code>Start the application:
<code># Log in as www
cd /data/www/ivweb.io
# Install project dependencies
npm install
# Launch the app with forever
forever start app.js
# Check running processes
forever list
# View logs in real time
# tail -f XXX.log</code>Finally, configure Nginx to proxy the Node app and restart Nginx. The site is now live.
Tencent IMWeb Frontend Team
IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.