I recently purchased a new Ubuntu server for my startup. Here's a concise guide, taking about 5 minutes, to set it up.
Setting up a new server can be quite rewarding. Following these steps, your server will be ready to host a web app created with Node.js and Nginx, and it can synchronize with your existing repository if necessary.
First, let's update the apt package list by running:
Enable essential ports
In your provider’s panel, enable these ports:
- 80 for http
- 443 for https
- 22 for ssh
Install Nginx
Execute the command below to install Nginx, a popular web server:
To verify the Nginx service status, use:
A successful installation will display output similar to this:
Install Node framework
Run these commands to install Node.js and npm:
Verify the installations with:
To update Node.js (recommended to version 16 or later), execute:
Install Git
Run this command if git not installed.
Next, let’s generate the ssh key. Skip this step if you do not need to work with your remote repo on this server.
Retrieve the public key with:
Add this key to your GitHub account under SSH keys settings.
Install PM2
To manage our process we can use PM2.
Now you can start your project. Switch to your projecy directory, and run:
Replace “yarn” and second “start” with your actuall command.
Config Nginx & SSL
⚠️ Note: Replace 'ygeeker.com.cn' with your domain.
Create the Nginx configuration file:
Type in the website config:
Create a symbolic link to enable this configuration:
It’s not recommended to directly create config file under sites-enabled directory.
To dive deeper about symbolic link on Linux you could read Understanding Linux Kernel.
Ensure DNS settings are correctly configured to point to your server.
For more on Certbot, visit this page.
Use Github action for automention
We’ll create a github action to let the production always use latest code from master branch. Let’s start with writting github action file.
Create a sync-to-server.yml under .github/workflows
Then enable action for your github repo on this page.
In your github repo, create three environemnt varibles for SSH connection at this page:
Further
To maximize your server’s capabilities, consider:
- Hosting a Jitsi Meet video conference service
- Running a Minecraft server
- Setting up a media streaming service with Jellyfin or Plex
- And more…