logo
0
0
WeChat Login

Nginx on Ubuntu 24.04 Docker Image

This project provides a Docker image based on Ubuntu 24.04 with Nginx and related applications pre-installed.

What's Included

Core Components

  • Nginx - High-performance web server
  • Nginx Extras - Additional modules and tools for enhanced functionality

Supporting Tools

  • curl & wget - For testing connections and downloading files
  • certbot & python3-certbot-nginx - SSL/TLS certificate management with Let's Encrypt
  • htop - Interactive process viewer
  • vim - Text editor for configuration changes
  • unzip - File extraction utility

Features

  • Ubuntu 24.04 Base - Latest LTS version with security updates
  • Optimized Image Size - Cleaned package caches and lists
  • HTTP/HTTPS Support - Ports 80 and 443 exposed
  • Test Page - Basic HTML page included for quick testing
  • Foreground Mode - Proper container operation with nginx running in foreground

Quick Start

Build the Image

docker build -t nginx-ubuntu .

Run the Container

docker run -p 80:80 -p 443:443 nginx-ubuntu

Run with Volume Mount (for custom configuration)

docker run -p 80:80 -p 443:443 \ -v /path/to/your/nginx.conf:/etc/nginx/nginx.conf \ -v /path/to/your/html:/var/www/html \ nginx-ubuntu

Configuration

Nginx Configuration

  • Default configuration location: /etc/nginx/nginx.conf
  • Site configurations: /etc/nginx/sites-available/
  • Document root: /var/www/html
  • Log files: /var/log/nginx/

SSL Certificates

To use SSL certificates with Certbot:

  1. Mount your domain and email environment variables:
docker run -p 80:80 -p 443:443 \ -e DOMAIN=yourdomain.com \ -e EMAIL=admin@yourdomain.com \ nginx-ubuntu
  1. Run Certbot inside the container:
docker exec -it <container_id> certbot --nginx -d yourdomain.com

Usage Examples

Basic Web Server

After running the container, access the test page at:

http://localhost

Custom HTML Content

Replace the default index.html with your content:

docker run -p 80:80 \ -v /path/to/your/html:/var/www/html \ nginx-ubuntu

Reverse Proxy Setup

Create a custom nginx.conf for reverse proxy:

events {} http { upstream backend { server backend-service:3000; } server { listen 80; location / { proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } }

Development

Building the Docker Image

# Build with tag docker build -t nginx-ubuntu:latest . # Build without cache docker build --no-cache -t nginx-ubuntu .

Debugging

# Access container shell docker exec -it <container_id> /bin/bash # View nginx logs docker exec -it <container_id> tail -f /var/log/nginx/access.log docker exec -it <container_id> tail -f /var/log/nginx/error.log # Test nginx configuration docker exec -it <container_id> nginx -t

Environment Variables

VariableDefaultDescription
DEBIAN_FRONTENDnoninteractivePrevents interactive prompts during package installation

Docker Compose Example

version: '3.8' services: nginx: build: . ports: - "80:80" - "443:443" volumes: - ./html:/var/www/html - ./nginx.conf:/etc/nginx/nginx.conf restart: unless-stopped

Security Considerations

  • The image includes tools like vim and htop for development convenience
  • For production use, consider removing unnecessary packages
  • Always use HTTPS in production environments
  • Keep your nginx configuration secure and up-to-date

License

This project is provided as-is for educational and development purposes.

About

No description, topics, or website provided.
Language
Dockerfile100%