<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cedar Daniel</title>
    <description>The latest articles on DEV Community by Cedar Daniel (@cedar_daniel_1d95c709d304).</description>
    <link>https://dev.to/cedar_daniel_1d95c709d304</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1659232%2F902703f1-4bdc-45d2-b5c8-cd67c45538fe.jpg</url>
      <title>DEV Community: Cedar Daniel</title>
      <link>https://dev.to/cedar_daniel_1d95c709d304</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cedar_daniel_1d95c709d304"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Cedar Daniel</dc:creator>
      <pubDate>Mon, 20 Oct 2025 11:01:00 +0000</pubDate>
      <link>https://dev.to/cedar_daniel_1d95c709d304/-82</link>
      <guid>https://dev.to/cedar_daniel_1d95c709d304/-82</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/cedar_daniel_1d95c709d304" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1659232%2F902703f1-4bdc-45d2-b5c8-cd67c45538fe.jpg" alt="cedar_daniel_1d95c709d304"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/cedar_daniel_1d95c709d304/setting-up-nginx-as-a-reverse-proxy-for-your-nest-js-microservices-5bk7" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Setting Up NGINX as A Reverse Proxy for your Nest JS Microservices&lt;/h2&gt;
      &lt;h3&gt;Cedar Daniel ・ Oct 16&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#nginx&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>programming</category>
      <category>nginx</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Setting Up NGINX as A Reverse Proxy for your Nest JS Microservices</title>
      <dc:creator>Cedar Daniel</dc:creator>
      <pubDate>Thu, 16 Oct 2025 16:37:19 +0000</pubDate>
      <link>https://dev.to/cedar_daniel_1d95c709d304/setting-up-nginx-as-a-reverse-proxy-for-your-nest-js-microservices-5bk7</link>
      <guid>https://dev.to/cedar_daniel_1d95c709d304/setting-up-nginx-as-a-reverse-proxy-for-your-nest-js-microservices-5bk7</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fef4vebs6qwftodzenl0a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fef4vebs6qwftodzenl0a.jpg" alt=" " width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When building applications with NestJS, it's common to break features into microservices for better scalability, maintainability, and fault isolation. While this approach brings flexibility, it also introduces complexity in how clients communicate with multiple services. That's where NGINX comes in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is NGINX?&lt;/strong&gt;&lt;br&gt;
NGINX is a high-performance web server and reverse proxy widely used to handle routing, load balancing, SSL termination, and request buffering. By placing NGINX in front of your NestJS microservices, you create a single entry point that can manage traffic efficiently, hide internal service structure from the outside world, and improve overall security and performance.&lt;/p&gt;

&lt;p&gt;In this article, we'll walk through the process of setting up NGINX as a reverse proxy for your NestJS microservices. We'll cover why this setup is useful, how to configure NGINX to route traffic to different services, and best practices for production-ready deployments. Whether you're running on Docker, Kubernetes, or a bare-metal server, the same principles apply.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Spin Up New Nest JS Application&lt;/strong&gt;&lt;br&gt;
We'll do this by leveraging the Nest JS CLI&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nest new nestjs-nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Convert App to Monorepo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We'll do this by generating a new app within our current app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nest generate app app-b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's rename the original app to app-a for clarity.&lt;/p&gt;

&lt;p&gt;1.Rename the folder &lt;code&gt;apps/my-monorepo&lt;/code&gt; to apps/app-a.&lt;/p&gt;

&lt;p&gt;2.Open the &lt;code&gt;nest-cli.json&lt;/code&gt; file in the root directory. You will see an entry for "my-monorepo". Change its name to "app-a".&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;nest-cli.json&lt;/code&gt; should now look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "apps/app-a/src",
  "compilerOptions": {
    "deleteOutDir": true,
    "webpack": true,
    "tsConfigPath": "apps/app-a/tsconfig.app.json"
  },
  "monorepo": true,
  "root": "apps/app-a",
  "projects": {
    "app-a": {
      "type": "application",
      "root": "apps/app-a",
      "entryFile": "main",
      "sourceRoot": "apps/app-a/src",
      "compilerOptions": {
        "tsConfigPath": "apps/app-a/tsconfig.app.json"
      }
    },
    "app-b": {
      "type": "application",
      "root": "apps/app-b",
      "entryFile": "main",
      "sourceRoot": "apps/app-b/src",
      "compilerOptions": {
        "tsConfigPath": "apps/app-b/tsconfig.app.json"
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll update the code in the &lt;code&gt;app.service.ts&lt;/code&gt; of service &lt;strong&gt;A&lt;/strong&gt; and &lt;strong&gt;B&lt;/strong&gt; respectively to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  getHello(): string {
    return 'Hello from service A!';
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  getHello(): string {
    return 'Hello from service B!';
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Dockerize Both Applications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a .dockerignore File&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we'll create a &lt;code&gt;.dockerignore&lt;/code&gt; file in the root directory of our nestjs-nginx project. This prevents unnecessary files from being copied into our Docker images, which speeds up the build process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Dependency directories
node_modules/

# Build artifacts
dist/

# Git
.git
.gitignore

# Docker
Dockerfile
docker-compose.yml

# IDE/Editor specific
.idea
.vscode

# Log files
*.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create a Dockerfile for app-a&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we'll create a Dockerfile inside the apps/app-a/ directory.&lt;br&gt;
&lt;code&gt;apps/app-a/Dockerfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ---- Build Stage ----
FROM node:20-alpine AS builder

WORKDIR /usr/src/app

# Copy root dependencies and config
COPY package*.json tsconfig*.json nest-cli.json ./

# Copy specific app and shared libs
COPY apps/app-a ./apps/app-a
COPY libs ./libs

# Install dependencies and build the app
RUN npm install
RUN npm run build app-a

# ---- Production Stage ----
FROM node:20-alpine AS production

WORKDIR /usr/src/app

# Copy only necessary files from builder
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist/apps/app-a ./dist

EXPOSE 3000

CMD ["node", "dist/main.js"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Create a Dockerfile for app-b&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, create a nearly identical &lt;code&gt;Dockerfile&lt;/code&gt; inside the &lt;code&gt;apps/app-b/&lt;/code&gt; directory. The only changes are the lines for building app-b and copying its specific dist folder.&lt;br&gt;
&lt;code&gt;apps/app-b/Dockerfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ---- Build Stage ----
FROM node:20-alpine AS builder

WORKDIR /usr/src/app

COPY package*.json tsconfig*.json nest-cli.json ./
COPY apps/app-b ./apps/app-b
COPY libs ./libs

RUN npm install
RUN npm run build app-b

# ---- Production Stage ----
FROM node:20-alpine AS production

WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist/apps/app-b ./dist

EXPOSE 3001

CMD ["node", "dist/main.js"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Create the docker-compose.yml File&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the root of your nestjs-nginx project, create a docker-compose.yml file. This file will define and orchestrate your services.&lt;br&gt;
&lt;code&gt;docker-compose.yml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  app-a:
    build:
      context: .
      dockerfile: apps/app-a/Dockerfile
    ports:
      - '3000:3000'
    restart: always

  app-b:
    build:
      context: .
      dockerfile: apps/app-b/Dockerfile
    ports:
      - '3001:3001'
    restart: always
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Build and Run the Containers 🚀&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You're all set! Open your terminal at the root of the project and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker compose up --build -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We should be able to reach both apps at localhost:3000 and localhost:3001 respectively as shown below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwros9yy4shsshiyecqy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwros9yy4shsshiyecqy.png" alt="Service A" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3pjm1je1flmcbyd8mj7j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3pjm1je1flmcbyd8mj7j.png" alt="Service B" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Set Up Nginx!&lt;/strong&gt;&lt;br&gt;
In the root of our nestjs-nginx project, we create an nginx folder and inside we create a nginx.conf file and we set it up like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;events {}

http {
  # Define an "upstream" for each of your services.
  # Docker Compose lets you use the service name ('app-a', 'app-b') as a hostname.
  upstream app_a_server {
    server app-a:3000;
  }

  upstream app_b_server {
    server app-b:3001;
  }

  server {
    listen 80;

    # Route requests starting with /api/a to app-a
    location /app-a/ {
      # The rewrite rule strips the /api/a prefix before forwarding
      # e.g., /api/a/users becomes /users
      rewrite /app-a/(.*) /$1 break;
      proxy_pass http://app_a_server;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # Route requests starting with /api/b to app-b
    location /app-b/ {
      rewrite /app-b/(.*) /$1 break;
      proxy_pass http://app_b_server;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we update the docker-compose.yaml to spin up an nginx container and reference this file like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  app-a:
    build:
      context: .
      dockerfile: apps/app-a/Dockerfile
    ports:
      - '3000:3000'
    restart: always

  app-b:
    build:
      context: .
      dockerfile: apps/app-b/Dockerfile
    ports:
      - '3001:3001'
    restart: always

  nginx:
    image: nginx:latest
    container_name: nginx
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - '80:80'
    depends_on:
      - app-a
      - app-b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7: Rebuild Images&lt;/strong&gt;&lt;br&gt;
Now we rebuild the images and start up the containers like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker compose down -v

docker compose up --build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 8: Test Nginx Integration&lt;/strong&gt;&lt;br&gt;
We can proceed to reach the apps through Nginx again through &lt;strong&gt;&lt;a href="http://localhost/app-a" rel="noopener noreferrer"&gt;http://localhost/app-a&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="http://localhost/app-b" rel="noopener noreferrer"&gt;http://localhost/app-b&lt;/a&gt;&lt;/strong&gt; respectively&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F41p33fqik9rj8z4r5kus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F41p33fqik9rj8z4r5kus.png" alt="Service A" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpihy81z949yd6tfpx84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpihy81z949yd6tfpx84.png" alt="Service B" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this guide, we walked through how to use NGINX as a reverse proxy to route traffic between multiple NestJS services. You’ve learned how to structure your Docker containers, configure the nginx.conf, and test that each service is reachable through clean, unified endpoints. With this setup in place, you can now add more services or introduce HTTPS with minimal changes — making your microservice architecture production-ready.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>nginx</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
