We are 40% more affordable than other Hyperscalers! Sign up and avail $100 free credits now!!

AccuWeb.CloudAccuWeb.CloudAccuWeb.Cloud
Configure Docker, NGINX & SSL for Node.Js Applications
Post Category: Blog > Products > Applications Cloud

Troubleshooting and Configuring Docker, NGINX, and SSL for Node.js Applications on AccuWeb.Cloud

Deploying a Node.js application with Docker on AccuWeb.Cloud involves configuring HTTPS, managing domains, and setting up services like NGINX and load balancers. This guide addresses common challenges and provides solutions tailored to AccuWeb.Cloud’s Platform-as-a-Service (PaaS) environment, simplifying the integration of these components.

Docker Compose and Multi-Service Application Setup

AccuWeb.Cloud environments make deploying services like Express (Node.js), PostgreSQL, and Redis seamless through individual containers or Docker Compose, simplifying orchestration and service management. AccuWeb.Cloud’s marketplace also streamlines service deployment and management, allowing for easy setup and scaling of applications.

AccuWeb.Cloud Setup Tips

  • Docker CE Engine and Cluster: The platform provides Docker CE, enabling you to build custom Docker images and deploy them seamlessly. AccuWeb.Cloud’s marketplace also allows you to easily add PostgreSQL, Redis, and other application servers.
  • Automatic Load Balancer: Load balancing is handled automatically by AccuWeb.Cloud when you create your environment, ensuring traffic is properly routed without needing manual configuration.

To get started, let’s first focus on installing the necessary services. AccuWeb Cloud’s marketplace offers a convenient way to add essential services like PostgreSQL, Redis, and other application servers directly to your environment. Simply navigate to the marketplace section, browse available options, and select the services you need.

AccuWeb Cloud will handle the installation and configuration for you, ensuring they’re readily available for integration with your Node.js application. Once these services are set up, we can proceed to the troubleshooting and configuration steps.

Steps to install Docker Engine

Let’s install Docker Engine!

Step 1: Log in to your AccuWeb.Cloud account.

Step 2: Click “MarketPlace” at the top of the screen.

AccuWeb.Cloud Marketplace

Step 3: In the MarketPlace window, select “Dev & Admin Tools” under Applications and “Docker Engine CE.”

Step 4: Click “Install” to start the installation.

Install Docker Engine CE

Step 5: In the installation window, you’ll need to provide details about how you want your Docker Engine environment to be set up. You can choose the version of Docker you wish to install and decide how you want to deploy it:

Choose The Preferred Deployment Mode

Create a clean standalone engine: Set up a node with just a Docker daemon. Optionally, you can choose to install the Portainer UI for web-based management.

Create a clean standalone engine

Connect to an existing swarm cluster: Add the new Docker Engine container to an existing Docker Swarm cluster (as either a Manager or Worker) by providing the appropriate cluster Join Token and Host IP.

Connect to swarm cluster

Deploy containers from compose.yml: Automatically deploy an application from the specified custom repository.

Deploy containers from compose.yml

Environment Type a name for your environment.

  • Display Name (optional): Specify an alias for better differentiation within the Accuweb.cloud dashboard and SSH Gate.
  • Region: Select the data center location on which you want to create the Docker Engine. Here, we have selected US-NY-01 as an example.

Step 6: Click “Install” again and wait a few minutes for AccuWeb.Cloud to do all the necessary work, like setting up the environment, installing Docker Engine, and deploying your chosen image.

Step 7: Once done, you’ll see a confirmation message and an email connecting your engine to a group of Docker systems.

Step 8: Click “Close” to close the window, and then close the MarketPlace window.

Step 9: Docker Engine CE is successfully installed in the AccuWeb.Cloud.

Steps to install PostgreSQL

Step 1. Access the AccuWeb.Cloud dashboard and initiate the process of creating a New environment.

New Environment

Step 2. During the environment creation process, ensure that you select the appropriate application server, such as Apache PHP, and the PostgreSQL database option.

Step 3. Enter the environment name and click on the Create button.

Enter the Environment Name

Upon successful creation, you will receive a confirmation email containing the crucial database credentials, including the login and password details.

Login and Password Details

With these essentials in hand, you can seamlessly access your database through the user-friendly web admin panel to seamless integration with your PHP application.

Steps to install Redis Cluster

The Redis Auto-Clustering option in the topology wizard allows automatic installation and configuration. Here are the detailed steps to install and configure Redis Cluster using the Redis Cluster option:

Step 1. Login into the AccuWeb.Cloud dashboard and click on Marketplace.

Marketplace

Step 2. Look for the Redis Cluster option and click on Install.

Redis Cluster

Step 3. You will come across the installation frame, where you can input the number of nodes, choose whether to enable Horizontal Auto-Scaling, assign External IP Addresses to cluster nodes, provide a name for the environment, and Display Name.

Cluster Nodes

Step 4. Click Install when ready.

After the deployment, a success pop-up containing the Redis Cluster admin panel credentials will appear. Additionally, this same information will be sent to your email.

Redis Cluster Application

How to access Redis Cluster?

Access Redis Cluster using the admin panel

Once the cluster is ready, you can connect to the admin panel. From there, you can access cluster details and make necessary configurations and adjustments.

Redis Cluster using the admin panel

Access Redis Cluster using SSH connection (Web SSH)

You also have the option to establish an SSH connection (such as Web SSH) for making required changes. For instance, you can use the redis-cli tool and the password in the email to connect to the cluster and ensure its proper functionality.

  • Open the terminal and enter: redis-cli
  • Authenticate with the provided password: auth {passw0rd}
  • To confirm that the cluster is working correctly, enter cluster nodes

SSH Connection

This information is accessible from any cluster node, whether a Primary or Secondary node. The output will display the cluster nodes’ count, IDs, addresses, roles, and shards (hash slots) allocation for each node.

Introduction to Load Balancing

Load balancing is the process of distributing network traffic and workloads across multiple servers or components using a dedicated mechanism known as a load balancer.

In this platform, when application servers are scaled, a load balancer node is automatically added to distribute incoming requests among the backend servers. Additionally, users have the option to manually add and scale load balancer instances within the environment’s topology if needed.

Load Balancer Topology

The platform currently provides five managed load balancer stacks to choose from:

Load Balancer Topology

One of the most popular options is the open-source NGINX server, which is highly regarded for its exceptional performance, ensuring efficient application hosting. With NGINX, no extra configuration or setup is required.

NGINX is also known for its scalability, security features, and resource efficiency, making it an affordable and highly available solution for hosting applications. It comes with built-in Layer 7 load balancing and content caching.

Learn how to configure the NGINX Load Balancer in just a few minutes.

Steps to install Node.js Environment

Node.js Environment Hosting

Create a New Environment

Create a New Environment

To deploy a Node.js app, you must utilize the Topology Wizard, which is powerful & easy to use.

Navigate to the Node.js tab, select the necessary engine version for your application server, and add any additional software stack as needed. If necessary, modify other parameters such as cloudlets, node count, Public IPv4, etc. Once configured, click Install to begin the installation.

Node.js app Configure

Access Issues and SSL Configuration

Why Can’t I Access My Application via URL or Load Balancer?

Since AccuWeb.Cloud manages the load balancer automatically, access issues often stem from application or domain misconfigurations, particularly with SSL and CORS.

CORS/Helmet Issues

Misconfigured CORS and Helmet middleware in your Node.js app can block access from the frontend domain or prevent HTTP traffic.

Solution

Temporarily disable CORS and Helmet for troubleshooting. Once identified, configure CORS to allow traffic from your specific frontend domain, and adjust Helmet settings for HTTPS in production.

To temporarily disable CORS (Cross-Origin Resource Sharing) and Helmet for troubleshooting and later configure them correctly in a Node.js/Express environment, follow these steps:

1. Temporarily Disable CORS and Helmet

First, ensure you have installed the cors and helmet packages:


npm install cors helmet

Disable CORS

To disable CORS temporarily, you can comment out or modify the middleware in your app.js or server.js file:


// Comment this out to disable CORS
// const cors = require('cors');
// app.use(cors());

Disable Helmet

Similarly, to temporarily disable Helmet, comment out or modify the Helmet middleware:


// Comment this out to disable Helmet
// const helmet = require('helmet');
// app.use(helmet());

2. Troubleshooting the Issue

With CORS and Helmet disabled, proceed with your troubleshooting. This will help you identify whether the issue is related to these configurations.

3. Configure CORS for Specific Domain

Once the issue is identified, you should configure CORS to allow traffic from your specific frontend domain:


const cors = require('cors');

const corsOptions = {
origin: 'https://your-frontend-domain.com', // Replace with your frontend domain
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization'],
};

app.use(cors(corsOptions));

4. Configure Helmet for Production

After re-enabling Helmet, configure it for secure HTTPS use in production:


const helmet = require('helmet');

// Customize Helmet for production
app.use(
helmet({
contentSecurityPolicy: false, // Optional: customize content security policy
})
);

// Enable HTTPS in production
if (process.env.NODE_ENV === 'production') {
app.use(helmet.hsts({ maxAge: 31536000 })); // Enable HSTS for one year
}

5. Restart the Server

After making these changes, restart your Node.js server:


npm start

SSL Setup and HTTPS Access

If you’re able to access your app through the default URL format (e.g., https://dockerXXXX-env172XXXXXX27.us-la-01.awcompute.com/) but face issues with custom domains, the problem likely lies in the SSL certificate setup.

Solution

Use the Let’s Encrypt SSL add-on available in AccuWeb.Cloud’s marketplace to automatically provision SSL certificates for your custom domain. This add-on simplifies the process of obtaining and installing SSL certificates, ensuring secure HTTPS connections for your application.

AccuWeb.Cloud’s built-in load balancer streamlines Docker Container Hosting Node.js application deployment and management by taking care of traffic distribution, SSL termination, and other critical functions. Instead of configuring NGINX as a separate Docker image, you can direct your domain’s DNS records to the AWC load balancer’s IP address. This setup ensures that your Node.js application, running in a Docker container, is automatically accessible through your custom domain, eliminating the need for complex NGINX configurations and providing a smooth user experience.

DNS and Domain Configuration

To ensure your domain correctly points to the load balancer or public IP, you need to configure your DNS settings properly.

  • A Record: Points your domain (e.g., your-domain.com) to the IP address of your load balancer.
  • CNAME Record: Points subdomains (e.g., www.your-domain.com) to the main domain.

For more detailed guidance on domain registration, refer to this guide on Custom Domain Name Registration.

AccuWeb.Cloud handles most configurations automatically, including setting up load balancers and SSL certificates to ensure HTTPS access across your custom domains.

Handling Multiple Node.js Deployments

Common Issues with Node.js Deployments Over HTTPS

If you’ve deployed your Node.js app using Docker and manual installation methods, and both work over HTTP but not HTTPS, this is usually due to SSL certificate misconfigurations or routing issues.

Solution: Fixing SSL Certificate and Routing Issues

  • Ensure that the SSL certificate is properly installed for both deployments.
  • Verify that the NGINX configuration or load balancer is routing HTTPS traffic to the correct ports (typically port 443 for HTTPS).

Importing Docker Images into AccuWeb.Cloud Environments

In addition to standard deployment processes, AccuWeb.Cloud offers flexibility when it comes to Docker image management. With Docker Container Hosting, you can import an existing image into your environment or use AccuWeb.Cloud’s marketplace services like Docker CE/Swarm to create a cluster and manage your containers.

Option 1: Import Docker Image from the “New Environment ” Section

AccuWeb.Cloud provides an intuitive interface where you can directly import custom Docker images into your environment. Here’s how you can proceed:

1. Navigate to the “New Environment” Section: This is where you configure your AccuWeb.Cloud environment.

2. Select the “Custom” tab: You can upload or point to a Docker image stored in a container registry (e.g., Docker Hub, AWS ECR, or a private repository).

Custom Tab Select Image

3. Deploy the Image: Once imported, your Docker container will be available for deployment and scaling across the AccuWeb.Cloud infrastructure.

This option is ideal if you already have a pre-built Docker image and want to deploy it without additional service setup.

Option 2: Create a Docker CE/Swarm Cluster via Marketplace

Alternatively, you can use the Docker CE (Community Edition) or Docker Swarm cluster available in the AccuWeb.Cloud marketplace. This allows for more control over container orchestration and scaling.

  • Install Docker CE/Swarm via Marketplace: The marketplace offers Docker CE or Swarm as an app container, simplifying cluster creation.
  • Import Your Image Using Docker Commands: Once the Docker CE/Swarm environment is set up, you can manage containers using standard Docker CLI commands.

docker pull your-image-name:tag
docker run -d -p 8080:80 your-image-name

This option gives you more granular control over the container environment and is well-suited for complex, multi-container setups where advanced orchestration is required.

Simplifying Node.js Development with Docker on AccuWeb.Cloud

AccuWeb.Cloud empowers you to streamline your Node.js development workflow with Docker. This guide compiles essential resources to get you started quickly:

  1. Deploying Docker in a Flash (60 seconds):
    • Learn the fundamentals of deploying Docker on AccuWeb.Cloud in a minute.
    • Deploy Docker in 60 seconds with AccuWeb.Cloud
  2. Building and Deploying Your Application:
    • Step-by-step guide on building Docker images and deploying within AccuWeb.Cloud.
    • Deploy Application through Docker
  3. Managing Docker Engine Connections:
    • Methods for managing your Docker Engine instances within the AccuWeb.Cloud platform.
    • Docker Engine Connection and Management
  4. Migrating Existing Docker Applications:
    • Seamless migration process for Docker applications to AccuWeb.Cloud.
    • Migrate Docker Before Shutdown
  5. Mastering Docker Engine Deployment:
    • Advanced topics on deploying applications using Docker Engine on AccuWeb.Cloud.
    • Docker Engine Deployment

Conclusion

Deploying Node.js applications using Docker or manual methods on AccuWeb.Cloud can be streamlined with the platform’s PaaS features and marketplace. Here’s a summary of key steps to enable HTTPS access:

  1. Use Docker Compose or manual methods to manage services (optional, but recommended).
  2. Leverage AccuWeb.Cloud’s marketplace to automatically configure NGINX, SSL, and load balancing.
  3. Ensure DNS records point to the correct IP or load balancer.
  4. Use the Let’s Encrypt SSL add-on for automatic certificate provisioning.

By properly configuring NGINX as a reverse proxy and taking advantage of AccuWeb.Cloud’s built-in services, you can securely deploy and access your Node.js app over HTTPS.