DEV Community

Theodor Heiselberg
Theodor Heiselberg

Posted on

4

VS Code devcontainer and Nginx

Let's get started with using Nginx

The purpose of this post is to show how one can get up and running with a playground for Nginx.

This is not a toturial for usning Nginx.

(# TODO: Add ssh using uptime robot)

You'll need these ingredients to get up and running:

Image description

.devcontainer/devcontainer.json

{
    "name": "nginx-playground",
    "service": "dev-machine",
    "dockerComposeFile": "docker-compose.yml",
    "workspaceFolder": "/workspace",
    "mounts": [
        "source=${localWorkspaceFolder}/.devcontainer/.nginx,target=/usr/share/nginx/,type=bind"
    ],
    "postStartCommand": "nginx"
}
Enter fullscreen mode Exit fullscreen mode

.devcontainer/docker-compose.yml

name: nginx-playground-dc

services:
  dev-machine:
    build: 
      context: .
      dockerfile: Dockerfile.nginx
    volumes:
      - ..:/workspace
    networks:
      - internal
    ports:
      - "8472:80"
    command: ["sleep", "infinity"]

networks:
  internal:
    driver: bridge
Enter fullscreen mode Exit fullscreen mode

.devcontainer/Dockerfile.nginx

FROM nginx:alpine

EXPOSE 80
Enter fullscreen mode Exit fullscreen mode

.devcontainer/.nginx/html/index.html

<!DOCTYPE html>
    <body>Hello</body>
</html>
Enter fullscreen mode Exit fullscreen mode

.devcontainer/.nginx/nginx.conf/nginx.conf

events {}

http {
    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}

location /nginx_status {
    stub_status on;
    allow 127.0.0.1;  # Restrict access to localhost for security
    deny all;
}
Enter fullscreen mode Exit fullscreen mode

Now run that devcontainer and open a browser on your host machine:

Image description

Or from the host machines terminal run:
curl http://localhost:8472

Image description

Quickstart image

Django MongoDB Backend Quickstart! A Step-by-Step Tutorial

Get up and running with the new Django MongoDB Backend Python library! This tutorial covers creating a Django application, connecting it to MongoDB Atlas, performing CRUD operations, and configuring the Django admin for MongoDB.

Watch full video →

Top comments (0)

AI Agent image

How to Build an AI Agent with Semantic Kernel (and More!)

Join Developer Advocate Luce Carter for a hands-on tutorial on building an AI-powered dinner recommendation agent. Discover how to integrate Microsoft Semantic Kernel, MongoDB Atlas, C#, and OpenAI for ingredient checks and smart restaurant suggestions.

Watch the video 📺

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay