DEV Community

Cover image for Simple reverse proxy using docker/nginx
Ethan
Ethan

Posted on

4 2

Simple reverse proxy using docker/nginx

Introduction

Hello! I needed to share a local service that was running in one of my Virtual Machines across my company's VPN. I didn't want to set up the connection inside my virtual machine so for this I used Nginx's reverse proxy.


Requirements

  • Docker
  • Docker-Compose

First I created the default config file for Nginx:

# defaults.conf 
server {
  listen [Company VPN IP]];
  server_name [Company VPN IP]];

  location / { 
    include /etc/nginx/includes/proxy.conf;
    proxy_pass [VPN Service Address]]
    allow all;
  }   

  access_log off;
  error_log off;

  charset UTF-8;
}
Enter fullscreen mode Exit fullscreen mode

Pretty simple file, I also didn't need any of the log files so I turned them off.

Next I had to create the proxy config file:

# includes/proxy.conf
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
Enter fullscreen mode Exit fullscreen mode

Finally the docker files!

# Dockerfile
FROM nginx

COPY ./includes /etc/nginx/includes/
COPY ./default.conf /etc/nginx/conf.d/default.conf
Enter fullscreen mode Exit fullscreen mode
# docker-compose.xml
version: '3' 
services:
  proxy:
    build: ./
    network_mode: 'host'
Enter fullscreen mode Exit fullscreen mode

Pretty simple, as I wasn't using anything on port 80 I decided to set the network_mode to "host".

Finally to build and start!

docker-compose build && docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

With this I was able to view the service running on my virtual vachine via the company's VPN connection. :)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay